-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.asm
91 lines (74 loc) · 2.76 KB
/
main.asm
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
; kernal routines
CHROUT = $ffd2
GETIN = $ffe4
PLOT = $fff0
READST = $ff8a
; char codes
CHR_CLR_HOME = 147
; color codes
COLOR_BLACK = 0
COLOR_WHITE = 1
COLOR_RED = 2
COLOR_CYAN = 3
COLOR_PURPLE = 4
COLOR_GREEN = 5
COLOR_BLUE = 6
COLOR_YELLOW = 7
; zero page variables
cur_color = $0286 ; color for CHROUT
;*****************************************************************
; start prg
;*****************************************************************
.byt $01,$10 ; PRG file header (starting address of the program)
.org $1001 ; start of basic program
;*****************************************************************
; basic stub
;*****************************************************************
; stub basic program
;
; 2015 SYS4109
;
.word bend ; next line link
.word 2015 ; line number
.byte $9e,52,49,48,57 ; sys4109 (4096+13 = bytes of basic program)
.byte 0 ; end of line
bend: .word 0 ; end of program
;*****************************************************************
; main program
;*****************************************************************
start:
jsr clear_screen ; jump save return -> clear_screen
ldy #COLOR_YELLOW ; init y = COLOR_YELLOW
@mloop:
tya ; Transfer y register to accumulator (a)
sta cur_color ; Store accumulator (a) -> cur_color (set color CHROUT)
jsr print_message ; jump save return -> print_message
dey ; y = y - 1
bne @mloop ; Branch if not equal (Z=0) (if y <> 0 goto @mloop)
; Restore default color
lda #COLOR_BLUE ; Load a = COLOR_BLUE (default color)
sta cur_color ; Store accumulator (a) -> cur_color (set color CHROUT)
rts ; exit (Return from subroutine)
clear_screen:
lda #CHR_CLR_HOME ; Load a = CHR_CLR_HOME (147)
jsr CHROUT ; jump save return -> CHROUT (print a)
rts ; Return from subroutine
print_message:
ldx #0 ; init x = 0
@pmloop:
lda message,x ; Load a = message + x
beq exit ; Branch if the Zero flag is set (Z=1) (if a == 0 goto exit)
jsr CHROUT ; jump save return -> CHROUT (print a)
inx ; x = x + 1
bne @pmloop ; Branch if not equal (Z=0) goto @pmloop
exit:
lda #13 ; Load a = 13 (Carriage Return)
jsr CHROUT ; jump save return -> CHROUT (print a)
lda #10 ; Load a = 10 (Line Feed)
jsr CHROUT ; jump save return -> CHROUT (print a)
rts ; Return from subroutine
;*****************************************************************
; data
;*****************************************************************
; H E L L O V I C 2 0 .
message: .byte 72,69,76,76,79,32,86,73,67,50,48,46,$00