aboutsummaryrefslogtreecommitdiffstats
path: root/data/rambasic.asm
blob: 3b7323ffd6827cffc3e899a4c0e346c7777b9bec (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
; This code must be position-independent.

	org 0
entry:				; On entry HL points here
	inc h			; Buffer at +256 bytes
	push hl			; Buffer address
	xor a
	ld l,a
	ld h,a
	; DE -> ROM address
	
	; Wait for NMI before copying the first chunk
	di
	halt

	; Test for RAM
	inc a			; A = 1
	out (7),a
	ld c,(hl)
	add c
	ld (hl),a
	ld a,(hl)
	sub c
	jr z,error		; A = 0, HL = 0 on error

copy:
	xor a
	out (7),a

	; Copy to buffer
	pop de			; Buffer address
	push de			; Buffer address
	push hl			; ROM address
	ld bc,256
	ldir

	inc a			; A = 1
	out (7),a

	; Copy from buffer
	pop de			; ROM address
	pop hl			; Buffer address
	push hl			; Buffer address
	inc b			; BC <- 256
	ldir

	ex de,hl		; ROM address -> HL

	bit 7,h
	jr z,copy

	; A = 1, HL != 0

error:
	out (7),a
	ei

	ret