-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminicalc64.s
More file actions
151 lines (111 loc) · 2.91 KB
/
Copy pathminicalc64.s
File metadata and controls
151 lines (111 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
include "64cube.inc"
Screen EQU $f000
EntryAddr EQU (Screen + 46 * 64 + 4) ; Address to start drawing entry digits
StackAddr EQU (Screen + 36 * 64 + 4) ; Address to start drawing stack digits
MaxEntryStack EQU $20
ENUM $0
r0 dsb 1 ; general purpose ZP variables
r1 dsb 1
r2 dsb 1
r3 dsb 1
r4 dsb 1
r5 dsb 1
r6 dsb 1
r7 dsb 1
a0 dsw 1 ; general purpose address
ready dsb 1 ; indicates NMI has fired
; General pointers
source dsw 1 ; source pointer
dest dsw 1 ; destination pointer
; Joypad handling
heldInputs dsb 1 ; inputs being held
newInputs dsb 1 ; new inputs pressed this frame
; Actual program state variables
cursorX dsb 1
cursorY dsb 1
entryCursor dsb 1 ; position of current entry digit (0-3)
entryDigits dsb 4 ; one byte per digit being entered
sPtr dsb 1 ; stack pointer
stack dsb MaxEntryStack ; 2 bytes per entry (always 16bit entries)
; (only the most recent 5 entries are visible)
scratch dsb 4 ; 'large' scratch buffer (used for staging digits to print)
ENDE
org $200
Boot:
sei
ldx #$ff
txs
lda #>Screen >> 4
sta VIDEO
lda #>Palette
sta COLORS
; Unpack 1bpp digit tiles as color 3
lda #<DigitTiles
sta dest
lda #>DigitTiles
sta dest+1
lda #3
sta r0
jsr UnpackDigitTiles
; Unpack 1bpp digit tiles as color 2
lda #<DigitTilesDim
sta dest
lda #>DigitTilesDim
sta dest+1
lda #2
sta r0
jsr UnpackDigitTiles
lda #<BackgroundTiles2bpp
sta source
lda #>BackgroundTiles2bpp
sta source+1
lda #<Screen
sta dest
lda #>Screen
sta dest+1
jsr Unpack2bppScreen ; Draw the main background
_setw IRQ, VBLANK_IRQ
cli
Main:
lda ready ; Wait until vblank has fired
beq Main
lda #1 ; DrawCursor with color 0 to clear it
sta r0
jsr DrawCursor
jsr ReadInputs
lda #2 ; DrawCursor with color 3 at new location
sta r0 ; (might not have changed, but that's fine)
jsr DrawCursor
lda #0 ; Clear vblank flag
sta ready
jmp Main
; NMI Handler
IRQ:
pha
lda #1
sta ready ; Flag that vblank fired
pla
rti
; Include additional source files
include operations.s
include drawing.s
include unpack.s
org $0D00 ; this must be page aligned for the palette copy to work
Palette:
; 4 color palette
hex 000000 221133 338877 ffffff
; Location to unpack digit tiles to
; (Background tiles will be unpacked directly to the screen)
org $0E00
dsb 1 ; Include a padding byte so we can use <addr>-1 and stay on the page
; Empty tile (used to erase old digits)
DigitEmpty:
dsb 4*5 ; (assembler will zero fill this)
; Primary tiles used for digit entry (color 3)
DigitTiles:
dsb 4*80
; Dim tiles used for stack (color 2)
org $1000 ; new page to simplify DrawDigit
dsb 1 ; padding byte
DigitTilesDim:
dsb 4*80