CODE ASM SOUS RASM
; first we need to define some constant in order to use RMR and RMR2
; RMR tags
MODE_0 equ 0
MODE_1 equ 1
MODE_2 equ 2
MODE_3 equ 3
ROM_OFF equ %1100
ROM_BOTH equ 0
ROM_UP equ %100
ROM_LOW equ %1000
INTRESET equ %10000
macro RMR tags
ld bc,#7F80+{tags}
out (c),c
mend
; RMR2 tags
ROM0 equ 0
ROM1 equ 1
ROM2 equ 2
ROM3 equ 3
ROM4 equ 4
ROM5 equ 5
ROM6 equ 6
ROM7 equ 7
ASICOFF equ 0
ROM0000 equ 0
ROM4000 equ %01000
ROM8000 equ %10000
ASICON equ %11000
macro RMR2 tags
ld bc,#7FA0+{tags}
out (c),c
mend
; init cartridge output mode
buildcpr
; write in the very first ROM, which will be mapped simultaneously in #0000 and #C000 at boot
bank 0
here_we_go
; interrupt should be disabled but this allow the code to be used as software reset
di
; unlike Winape, at boot, a real Amstrad Plus is not in IM 1
im 1
RMR ROM_LOW|MODE_2 ; disable upper ROM, in case of software reset
; reset RAM mapping in case of software reset, again...
ld bc,#7FC0
out (c),c
; reset RAM
ld hl,#0000
ld bc,4
.reset_ram repeat 32 : push hl : rend : djnz .reset_ram : dec c : jr nz,.reset_ram
; preset PPI
ld bc,#F782 : out (c),c
ld b,#F4 : out (c),0
ld b,#F6 : out (c),0
; setup a screen (not the one when prompt Basic on CPC...)
ld bc,#BC00 : out (c),c : ld bc,#BD00+63 : out (c),c
ld bc,#BC01 : out (c),c : ld bc,#BD00+10 : out (c),c
ld bc,#BC02 : out (c),c : ld bc,#BD00+42 : out (c),c
ld bc,#BC03 : out (c),c : ld bc,#BD8E : out (c),c
ld bc,#BC04 : out (c),c : ld bc,#BD00+38 : out (c),c
ld bc,#BC06 : out (c),c : ld bc,#BD00+00 : out (c),c
ld bc,#BC07 : out (c),c : ld bc,#BD00+34 : out (c),c
ld bc,#BC09 : out (c),c : ld bc,#BD00+7 : out (c),c
ld bc,#BC0C : out (c),c : ld bc,#BD30 : out (c),c
ld bc,#BC0D : out (c),c : ld bc,#BD00 : out (c),c
; unlock asic
ld bc,#bc11
ld hl,asic_unlock_sequence
.unlock_asic
inc b
outi
dec c
jr nz,.unlock_asic
RMR2 ASICON|ROM0
; reset ASIC registers, in case of software reset...
ld sp,#8000
ld hl,#0000
ld b,l
.reset_asic repeat 32 : push hl : rend : djnz .reset_asic
;********************************************************************
; now we are in an almost proper state
;********************************************************************
ld hl,0
ld de,0
ld bc,16384
ldir
RMR ROM_OFF
ld hl,#C9FB : ld (#38),hl
ld hl,#6800 : ld (hl),1
ei
ld hl,#6421
reloop
ld de,#000
ld b,254
halt : nop 5
nop 64-7 : dec hl : ld (hl),255 : inc hl
rasta
repeat 16 : inc (hl) : rend : dec hl : ld (hl),b : inc hl : nop 6 : djnz rasta : nop
repeat 16 : inc (hl) : rend : dec hl : ld (hl),b : inc hl : nop 6 : nop 4
repeat 16 : inc (hl) : rend
jp reloop
asic_unlock_sequence defb #ff,#00,#ff,#77,#b3,#51,#a8,#d4,#62,#39,#9c,#46,#2b,#15,#8a,#cd,#ee