aboutsummaryrefslogtreecommitdiff
path: root/hello.s
blob: 8642218ccc0eb75d8920b4362acf679f8f9a5379 (plain)
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
152

 .export _main
 .include "atari.inc"

 sptr   = FR0
 scount = FR0+2

 .ifndef start_addr
 start_addr = $4000
 .endif

 .ifndef RAW
 .org start_addr - 6
 .word $ffff
 .word start_addr
 .word end_addr - 1
 .endif

 .org start_addr
print_addr:
 jsr pa
pa:         ; pull return address, print it (don't put it back on the stack)
 pla
 sec
 sbc #2     ; pa-1 was pushed, we want to print print_addr
 sta sptr   ; lo byte
 pla
 sbc #0
 sta sptr+1
 jsr printhex
 lda sptr
 jmp printhex
 rts

_main:
 ldx #1
 stx CRSINH
 lda #<str1
 ldx #>str1
 jsr printstr
 lda #' '
 jsr printa
 lda #<str2
 ldx #>str2
 jsr printstr
 lda #'.'
 jsr printa
 lda #EOL
 jsr printa
 lda #<addr_str
 ldx #>addr_str
 jsr printstr
 jsr print_addr
 lda #EOL
 jsr printa
 lda #<end_str
 ldx #>end_str
 jsr printstr
 lda #>(end_addr-1)
 jsr printhex
 lda #<(end_addr-1)
 jsr printhex
 lda #<memlo_str
 ldx #>memlo_str
 jsr printstr
 lda MEMLO+1
 jsr printhex
 lda MEMLO
 jsr printhex
 lda #<relax_str
 ldx #>relax_str
 jsr printstr
 jsr junksub

cycle:
 lda RTCLOK+2
 and #$f0
 ora #$06
 sta COLOR2
 jmp cycle

printstr:
 sta sptr
 stx sptr+1
 lda #0
 sta scount
strloop:
 ldy scount
 lda (sptr),y
 bne printchr
 rts
printchr:
 jsr printa
 inc scount
 bne strloop
 rts

 ; Subroutine: Print A register in hex.
printhex:
 pha           ; stash argument
 lsr           ; shift right 4 times,
 lsr           ;   to get the first hex digit
 lsr           ;   (aka nybble) into the bottom
 lsr           ;    4 bit positions.
 jsr printxdig ; print the top nybble.
 pla           ; restore original value...
 and #$0f      ; mask off high nybble
 ; fall through to print the 2nd digit.

 ; Subroutine: Print a nybble (A=0 to $0f) in hex.
printxdig:
 ora #$30 ; 0-9 now ASCII...
 cmp #$3a ; do we have A-F?
 bcc xok  ; if not, don't adjust it
 adc #$26 ; A-F now ASCII: $3a + $26 + 1 (carry always set) = $61 (a)
xok:
 ; fall through to print the digit.

 ; Subroutine: Print ATASCII character in A.
 ; Assumes IOCB #0 is opened on the E: device, which is how the
 ; Atari boots up. Uses "call-by-RTS" (weird looking but standard).
printa:
 tax
 lda ICPTH ; the print-one-byte vector for IOCB 0.
 pha
 lda ICPTL ; low byte of vector
 pha
 txa
 rts

junksub:
 .repeat 512
 nop
 .endrep
 lda #'O'
 jsr printa
 lda #'K'
 jmp printa

str1:      .byte "Hello",0
str2:      .byte "World",0
addr_str:  .byte EOL, "I am currently located at $",0
end_str:   .byte      "My code ends at           $",0
memlo_str: .byte EOL, "MEMLO is currently set to $",0
relax_str: .byte EOL, EOL, "Watchen das blinkenlights...",EOL,0

 .ifndef RAW
end_addr:
 .word INITAD
 .word INITAD+1
 .word _main
 .endif