aboutsummaryrefslogtreecommitdiff
path: root/checkmem.s
blob: ad67f50f2860ca4910441146489d6a36f509104c (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

; Memcheck needs to do this:

;1. If RAMTOP is >=$C0, go to step 6.
;2. Attempt to disable BASIC.
;3. Write some data to $A000, read it back (do twice with 2 different values)
;4. If we couldn't read back what we wrote, that means there really is a
;   cartridge plugged in. Go to step 8.
;5. Set RAMTOP to $C0.
;6. Do a GRAPHICS 0.
;7. Exit via RTS, so the rest of the game will load.
;8. Do a GRAPHICS 0.
;9. Print a "remove cartridge" message
;10. Wait for a keypress
;11. Exit to DOS (without loading the rest of the file)

;At no point do we look at RAMSIZ, since it can't be trusted under SDX.

;Note that when we reach step 6, RAMTOP is always $C0 (either it was,
;or we set it to that).

; cl65 -o checkmem.xex -t none checkmem.s

 .include "atari.inc"

start = $0600 ; use page 6 for now

; homebrew XEX header
 .word $ffff
 .word start
 .word end-1

 .org start

; message is "Need 48K, remove cartridge" in screen codes.
msg:
 .byte $2e, $65, $65, $64, $00, $14, $18, $2b
 .byte $0c, $00, $72, $65, $6d, $6f, $76, $65
 .byte $00, $63, $61, $72, $74, $72, $69, $64
 .byte $67, $65
msglen = * - msg - 1

S: .byte "S:",0

init:
;1. If RAMTOP is >=$C0, go to step 6.
 lda RAMTOP
 cmp #$c0
 bcs ramtop_ok

;2. Attempt to disable BASIC.
; set bit 1 of PORTB. No effect on 400/800/1200XL. Don't
; touch any other bits in PORTB!
 lda PORTB
 ora #$02
 sta PORTB

;3. Write some data to $A000, read it back (do twice with 2 different values)
;4. If we couldn't read back what we wrote, that means there really is a
;   cartridge plugged in. Go to step 8.
 lda #$AA
 sta $A000
 cmp $A000
 bne rom_present
 lsr
 sta $A000
 cmp $A000
 bne rom_present

;5. Set RAMTOP to $C0.
 lda #$c0
 sta RAMTOP

;6. Do a GRAPHICS 0.
;7. Exit via RTS, so the rest of the game will load.
ramtop_ok:
 jmp gr_0

;8. Do a GRAPHICS 0.
rom_present:
 jsr gr_0

;9. Print a "remove cartridge" message
 lda #<msg
 sta FR0
 lda #>msg
 sta FR0+1

 ldy #msglen
msgloop:
 lda (FR0),y
 sta (SAVMSC),y
 dey
 bpl msgloop

;10. Wait for a keypress
 sty CH ; y == $ff at this point, clear keyboard
 ; ...wait for a keystroke...
wait4key:
 cpy CH
 beq wait4key
 sty CH ; clear the key so DOS menu won't see it.

;11. Exit to DOS (without loading the rest of the file)
 jmp (DOSVEC)

gr_0:
 ldx #6*$10 ; CLOSE #6
 lda #CLOSE
 sta ICCOM,x
 jsr CIOV

 ; GRAPHICS 0
 ldx #6*$10 ; IOCB #6
 lda #OPEN
 sta ICCOM,x
 lda #$1c ; $c = read/write
 sta ICAX1,x
 lda #0   ; aux2 byte zero
 sta ICAX2,x
 lda #<S
 sta ICBAL,x
 lda #>S
 sta ICBAH,x
 jmp CIOV

end:
 .word INITAD
 .word INITAD+1
 .word init