aboutsummaryrefslogtreecommitdiffstats
path: root/data/rambasic.asm
diff options
context:
space:
mode:
Diffstat (limited to 'data/rambasic.asm')
-rw-r--r--data/rambasic.asm58
1 files changed, 58 insertions, 0 deletions
diff --git a/data/rambasic.asm b/data/rambasic.asm
new file mode 100644
index 0000000..3b7323f
--- /dev/null
+++ b/data/rambasic.asm
@@ -0,0 +1,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