353 lines
4.5 KiB
NASM
353 lines
4.5 KiB
NASM
' this program counts how many times
|
|
' the user pressed EXE key and moves
|
|
' the display with the arrow keys
|
|
|
|
|
|
' first, clean the variables we will use
|
|
' y coordinate
|
|
push,30
|
|
store,#17
|
|
' x coordinate
|
|
push,60
|
|
store,#16
|
|
' number
|
|
push,0
|
|
store,#15
|
|
|
|
' second, setup the interrupt handler and
|
|
' subscribe to the keyboard events
|
|
inth,.inth
|
|
sub,b1
|
|
' fall through
|
|
|
|
' now, wait, everything is in the event handler
|
|
.wait
|
|
halt
|
|
jmp,.wait
|
|
|
|
' function to draw what we want
|
|
.draw
|
|
' set the values
|
|
push,#17
|
|
push,#16
|
|
push,#15
|
|
store,#5
|
|
store,#6
|
|
store,#7
|
|
' clear screen
|
|
ext,x0c
|
|
' draw counter
|
|
call,.decdraw
|
|
' print vram
|
|
ext,x01
|
|
' return
|
|
jmp
|
|
|
|
' interrupt handler
|
|
.inth
|
|
' protect the interrupt handler
|
|
unsub,b1
|
|
' check event type
|
|
store,#10
|
|
' check if hardware
|
|
high,x4000
|
|
and,#10
|
|
jnt,.abort
|
|
' check if it's a keydown
|
|
high,x4000
|
|
xor,#10
|
|
eq_i,x1
|
|
jif,.keydown
|
|
' if it's not, then pop the data and exit
|
|
pop
|
|
jmp,.inthl
|
|
|
|
' keydown event handler
|
|
.keydown
|
|
store,#11
|
|
' check if it's EXE
|
|
push,31
|
|
eq_i,#11
|
|
jnt,.keydown2
|
|
' yes, increment, exit the inth and print
|
|
push,1
|
|
add_i,#15
|
|
store,#15
|
|
jmp,.inthl
|
|
' no, check for the arrow keys
|
|
.keydown2
|
|
' increment #16 if right
|
|
push,27
|
|
eq_i,#11
|
|
add_i,#16
|
|
store,#16
|
|
' decrement #16 if left
|
|
push,38
|
|
eq_i,#11
|
|
sub_i,#16
|
|
store,#16
|
|
' increment #17 if down
|
|
push,37
|
|
eq_i,#11
|
|
add_i,#17
|
|
store,#17
|
|
' decrement #17 if up
|
|
push,28
|
|
eq_i,#11
|
|
sub_i,#17
|
|
store,#17
|
|
' exit the handler
|
|
' fall through
|
|
|
|
' leaves the interrupt handler and redraws
|
|
.inthl
|
|
push,.draw
|
|
push,b0
|
|
sub,b1
|
|
stat_s,x2
|
|
' if that doesn't work, abort
|
|
' fall through
|
|
|
|
' kills the program
|
|
.abort
|
|
' set the abort flag
|
|
push,b1
|
|
stat_s,x3
|
|
' remove interrupt handler and halt
|
|
' the program won't probably go here
|
|
inth,-1
|
|
halt
|
|
|
|
' subroutine to draw dec number on screen
|
|
' #5 input number
|
|
' #6 x coordinate
|
|
' #7 y coordinate
|
|
' #8 temp
|
|
.decdraw
|
|
push,#5
|
|
store,#8
|
|
.decdraw2
|
|
' divide temp by 8
|
|
push,10
|
|
div_i,#8
|
|
dup
|
|
store,#8
|
|
' if it is null, stop
|
|
jnt,.decdraw3
|
|
' else, add 4 to the x coordinate
|
|
push,4
|
|
add_i,#6
|
|
store,#6
|
|
' continue the loop
|
|
jmp,.decdraw2
|
|
.decdraw3
|
|
' get digit
|
|
push,10
|
|
mod_i,#5
|
|
'draw digit to screen
|
|
store,#8
|
|
call,.decdigit
|
|
' add 4 to the y coordinate
|
|
push,4
|
|
sub_i,#6
|
|
store,#6
|
|
' get next digit
|
|
push,10
|
|
div_i,#5
|
|
' draw next digit
|
|
dup
|
|
store,#5
|
|
jif,.decdraw3
|
|
'return
|
|
jmp
|
|
|
|
' subroutine to draw a dec digit on screen
|
|
' #8 input digit
|
|
' #6 x coordinate
|
|
' #7 y coordinate
|
|
.decdigit
|
|
' draw C if the number isn't 2
|
|
push,2
|
|
neq_i,#8
|
|
cif,.dispC
|
|
' draw A if the number isn't 1 or 4
|
|
push,1
|
|
neq_i,#8
|
|
push,4
|
|
neq_i,#8
|
|
and_l
|
|
cif,.dispA
|
|
' draw B if the number isn't 5 or 6
|
|
push,5
|
|
neq_i,#8
|
|
push,6
|
|
neq_i,#8
|
|
and_l
|
|
cif,.dispB
|
|
' draw D if the number isn't 1, 4 or 7
|
|
push,1
|
|
neq_i,#8
|
|
push,4
|
|
neq_i,#8
|
|
push,7
|
|
neq_i,#8
|
|
and_l
|
|
and_l
|
|
cif,.dispD
|
|
' draw G if the number isn't 0, 1 or 7
|
|
push,0
|
|
neq_i,#8
|
|
push,1
|
|
neq_i,#8
|
|
push,7
|
|
neq_i,#8
|
|
and_l
|
|
and_l
|
|
cif,.dispG
|
|
' draw F if the number isn't 1, 2, 3 or 7
|
|
push,1
|
|
neq_i,#8
|
|
push,2
|
|
neq_i,#8
|
|
push,3
|
|
neq_i,#8
|
|
push,7
|
|
neq_i,#8
|
|
and_l
|
|
and_l
|
|
and_l
|
|
cif,.dispF
|
|
' draw E if the number is 0, 2, 6 or 8
|
|
push,0
|
|
eq_i,#8
|
|
push,2
|
|
eq_i,#8
|
|
push,6
|
|
eq_i,#8
|
|
push,8
|
|
eq_i,#8
|
|
or_l
|
|
or_l
|
|
or_l
|
|
cif,.dispE
|
|
'return
|
|
jmp
|
|
|
|
' subroutine to draw the A part of a segment
|
|
.dispA
|
|
' color COLOR_BLACK
|
|
push,1
|
|
' x2=x+2
|
|
push,2
|
|
add_i,#6
|
|
' x1=x
|
|
push,#6
|
|
' y=y
|
|
push,#7
|
|
' lineH
|
|
ext,x07
|
|
' return
|
|
jmp
|
|
|
|
' subroutine to draw the B part of a segment
|
|
.dispB
|
|
' color COLOR_BLACK
|
|
push,1
|
|
' y2=y+2
|
|
push,2
|
|
add_i,#7
|
|
' y1=y
|
|
push,#7
|
|
' x=x+2
|
|
push,2
|
|
add_i,#6
|
|
' lineV
|
|
ext,x08
|
|
' return
|
|
jmp
|
|
|
|
' subroutine to draw the C part of a segment
|
|
.dispC
|
|
' color COLOR_BLACK
|
|
push,1
|
|
' y2=y+4
|
|
push,4
|
|
add_i,#7
|
|
' y1=y+2
|
|
push,2
|
|
add_i,#7
|
|
' x=x+2
|
|
push,2
|
|
add_i,#6
|
|
' lineV
|
|
ext,x08
|
|
' return
|
|
jmp
|
|
|
|
' subroutine to draw the D part of a segment
|
|
.dispD
|
|
' color COLOR_BLACK
|
|
push,1
|
|
' x2=x+2
|
|
push,2
|
|
add_i,#6
|
|
' x1=x
|
|
push,#6
|
|
' y=y+4
|
|
push,4
|
|
add_i,#7
|
|
' lineH
|
|
ext,x07
|
|
' return
|
|
jmp
|
|
|
|
' subroutine to draw the E part of a segment
|
|
.dispE
|
|
' color COLOR_BLACK
|
|
push,1
|
|
' y2=y+4
|
|
push,4
|
|
add_i,#7
|
|
' y1=y+2
|
|
push,2
|
|
add_i,#7
|
|
' x=x
|
|
push,#6
|
|
' lineV
|
|
ext,x08
|
|
' return
|
|
jmp
|
|
|
|
' subroutine to draw the F part of a segment
|
|
.dispF
|
|
' color COLOR_BLACK
|
|
push,1
|
|
' y2=y+2
|
|
push,2
|
|
add_i,#7
|
|
' y1=y
|
|
push,#7
|
|
' x=x
|
|
push,#6
|
|
' lineV
|
|
ext,x08
|
|
' return
|
|
jmp
|
|
|
|
' subroutine to draw the G part of a segment
|
|
.dispG
|
|
' color COLOR_BLACK
|
|
push,1
|
|
' x2=x+2
|
|
push,2
|
|
add_i,#6
|
|
' x1=x
|
|
push,#6
|
|
' y=y+2
|
|
push,2
|
|
add_i,#7
|
|
' lineH
|
|
ext,x07
|
|
' return
|
|
jmp
|