Skip to content

Commit 045d0df

Browse files
committed
Example working
1 parent e07454e commit 045d0df

10 files changed

+604
-22
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"files.associations": {
3-
"*.s": "asm.6502"
3+
"*.s": "asm.6502",
4+
"*.i": "asm.6502"
45
},
56
"[asm.6502]": {
67
"editor.insertSpaces": false,

.vscode/tasks.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"label": "Build .prg",
88
"type": "shell",
9-
"command": "make",
9+
"command": "just build",
1010
"problemMatcher": [],
1111
"group": {
1212
"kind": "build",

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2024 Carsten Elton Sørensen
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Source files
22
ASM_SRCS = \
3+
display.s \
34
main.s
45

56
# Extra dependencies

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Introduction
2+
3+
This repository contains a demonstration of how to set up a project for the MEGA65 computer using the ASMotor toolchain.
4+
5+
It is not intended as an example of optimal, or even good, coding practices. It does demonstrate a few of the 45GS02 instructions, however.

src/display.i

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
INCLUDE ONCE
2+
3+
GLOBAL waitSOF
4+
GLOBAL clearScreen
5+
GLOBAL initDisplay
6+
7+
TEXT_SCREEN EQU $000800
8+
CHARS_PER_LINE EQU 41

src/display.s

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
INCLUDE "mega65.i"
2+
INCLUDE "zeropage.i"
3+
INCLUDE "display.i"
4+
5+
SCREEN_HEIGHT EQU 200
6+
7+
TOP_BORDER_POS EQU 42
8+
BOTTOM_BORDER_POS EQU TOP_BORDER_POS+SCREEN_HEIGHT*2-1
9+
10+
BORDER_WIDTH EQU 80
11+
12+
13+
; ---------------------------------------------------------------------------
14+
; -- Wait for start of field
15+
; ---------------------------------------------------------------------------
16+
SECTION "waitSOF",CODE
17+
waitSOF::
18+
; test MSB of raster Y position
19+
bit R_YSCL
20+
bpl waitSOF
21+
.loop
22+
bit R_YSCL
23+
bmi .loop
24+
rts
25+
26+
; ---------------------------------------------------------------------------
27+
; -- Initialize the first line of text and colour RAM.
28+
; ---------------------------------------------------------------------------
29+
SECTION "clearScreen",CODE
30+
clearScreen::
31+
; colour RAM
32+
ldq #COLOUR_RAM
33+
stq zp.tl0
34+
lda #$01
35+
bsr .clear
36+
37+
; text screen
38+
ldq #TEXT_SCREEN
39+
stq zp.tl0
40+
lda #32 ; space screen code
41+
.clear
42+
ldz #CHARS_PER_LINE-1
43+
.loop
44+
sta [zp.tl0],z
45+
dez
46+
bpl .loop
47+
48+
rts
49+
50+
51+
; ---------------------------------------------------------------------------
52+
; -- Initialise display registers to NTSC
53+
; ---------------------------------------------------------------------------
54+
SECTION "initDisplay",CODE
55+
initDisplay::
56+
ldz #0
57+
58+
stz R_BORDERCOL
59+
stz R_SCREENCOL
60+
61+
; 40 column
62+
stz R_VMODE
63+
lda #CHARS_PER_LINE
64+
sta R_CHRCOUNT
65+
stz R_LINESTEPL
66+
67+
; set border position
68+
lda #<TOP_BORDER_POS
69+
sta R_TBDRPOSL
70+
stz R_TBDRPOSH
71+
lda #<BOTTOM_BORDER_POS
72+
sta R_BBDRPOSL
73+
lda #>BOTTOM_BORDER_POS
74+
sta R_BBDRPOSH
75+
76+
; charset
77+
78+
; ROM charset at $001000
79+
stz R_CHARPTRLSB
80+
lda #$10
81+
sta R_CHARPTRMSB
82+
stz R_CHARPTRBNK
83+
84+
; text screen at TEXT_SCREEN
85+
lda #<TEXT_SCREEN
86+
sta R_SCRNPTRLSB
87+
lda #>TEXT_SCREEN
88+
sta R_SCRNPTRMSB
89+
lda #^TEXT_SCREEN
90+
sta R_SCRNPTRBNK
91+
92+
; set text position
93+
lda #<BORDER_WIDTH
94+
sta R_TEXTXPOSL
95+
lda #>BORDER_WIDTH
96+
sta R_TEXTXPOSH
97+
98+
; set borders
99+
lda #<TOP_BORDER_POS
100+
sta R_TEXTYPOSL
101+
lda #>TOP_BORDER_POS
102+
sta R_TEXTYPOSH
103+
104+
lda #<BORDER_WIDTH
105+
sta R_SDBDRWDL
106+
lda #>BORDER_WIDTH
107+
sta R_SDBDRWDH
108+
109+
; Scaling
110+
lda #120
111+
sta R_CHRXSCL
112+
lda #1
113+
sta R_CHRYSCL
114+
115+
; set NTSC mode
116+
lda #R_RASLINE0.PALNTSC
117+
sta R_RASLINE0
118+
119+
; set display generation
120+
lda #R_FNRASTERH.UPSCALE
121+
sta R_FNRASTERH
122+
stz R_MISC
123+
124+
rts

src/main.s

+108-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,98 @@
1+
INCLUDE "mega65.i"
2+
INCLUDE "zeropage.i"
3+
INCLUDE "display.i"
4+
15
VECTOR_IRQ_BRK EQU $FFFE
26
VECTOR_RESET EQU $FFFC
37
VECTOR_NMI EQU $FFFA
48

5-
9+
; ---------------------------------------------------------------------------
10+
; -- Main entry point
11+
; ---------------------------------------------------------------------------
612
SECTION "Main",CODE
7-
813
Entry::
914
sei
1015

1116
; Ensure we're in 40 MHz mode
1217
lda #$41
1318
sta $00
1419

15-
jsr initMemoryMap
20+
lda #<scrollText
21+
sta zp.scrolltext
22+
lda #>scrollText
23+
sta zp.scrolltext+1
24+
25+
bsr initMemoryMap
26+
bsr initDisplay
27+
bsr clearScreen
28+
29+
.main_loop
30+
bsr waitSOF
31+
bsr scroller
32+
bra .main_loop
33+
34+
35+
; ---------------------------------------------------------------------------
36+
; -- Scroller
37+
; ---------------------------------------------------------------------------
38+
SECTION "scroller",CODE
39+
scroller:
40+
; increase pixel position
41+
lda R_TEXTXPOSL
42+
dea
43+
cmp #80-16
44+
bne .bit_ok
45+
46+
; copy chars to the left
47+
ldq #TEXT_SCREEN
48+
bsr .copy
49+
ldq #COLOUR_RAM
50+
bsr .copy
51+
52+
ldq #TEXT_SCREEN+40
53+
stq zp.tl0
54+
55+
ldz #0
56+
.next_char
57+
lda (zp.scrolltext),z
58+
bne .got_char
1659

17-
.flash
18-
inc $d021
19-
bra .flash
60+
lda #<scrollText
61+
sta zp.scrolltext
62+
lda #>scrollText
63+
sta zp.scrolltext+1
2064

65+
bra .next_char
66+
.got_char
67+
and #~$40 ; "convert" ASCII to screen code
68+
sta [zp.tl0],z
69+
inw zp.scrolltext
70+
71+
lda #80
72+
.bit_ok
73+
sta R_TEXTXPOSL
74+
2175
rts
2276

77+
; copy CHARS_PER_LINE-1 bytes from Q+1 to Q
78+
.copy
79+
stq zp.tl0
80+
stq zp.tl1
81+
inq zp.tl1
82+
ldz #0
83+
.copy_loop
84+
lda [zp.tl1],z
85+
sta [zp.tl0],z
86+
inz
87+
cpz #CHARS_PER_LINE-1
88+
bne .copy_loop
89+
90+
rts
91+
92+
; ---------------------------------------------------------------------------
93+
; -- Initialize memory map
94+
; ---------------------------------------------------------------------------
95+
SECTION "initMemoryMap",CODE
2396
initMemoryMap:
2497
; Clear C65 memory map
2598
lda #$00
@@ -28,19 +101,9 @@ initMemoryMap:
28101
taz
29102
map
30103

31-
; Bank I/O in via C64 mechanism
32-
lda #$35
33-
sta $01
34-
35-
; Do MEGA65 / VIC-IV I/O knock
36-
lda #$47
37-
sta $d02f
38-
lda #$53
39-
sta $d02f
40-
41104
; Set IRQ vectors
42-
ldx #<emptyIrq
43-
ldy #>emptyIrq
105+
ldx #<.emptyIrq
106+
ldy #>.emptyIrq
44107
stx VECTOR_IRQ_BRK
45108
sty VECTOR_IRQ_BRK+1
46109
stx VECTOR_NMI
@@ -51,8 +114,33 @@ initMemoryMap:
51114
; End MAP sequence, thus allowing interrupts to occur again
52115
eom
53116

54-
rts
117+
; Bank I/O in via C64 mechanism
118+
lda #$35
119+
sta $01
120+
121+
; Do MEGA65 / VIC-IV I/O knock
122+
lda #$47
123+
sta R_KEY
124+
lda #$53
125+
sta R_KEY
55126

127+
; don't map rom
128+
lda #$00
129+
sta R_ROMEN
130+
131+
rts
56132

57-
emptyIrq:
133+
.emptyIrq:
58134
rti
135+
136+
137+
; ---------------------------------------------------------------------------
138+
; -- Data
139+
; ---------------------------------------------------------------------------
140+
141+
SECTION "Text",DATA
142+
scrollText:
143+
DB "THIS IS A DEMONSTRATION OF HOW TO SET UP A PROJECT USING THE ASMOTOR ASSEMBLER AND LINKER ... ",0
144+
145+
146+

0 commit comments

Comments
 (0)