News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_andymccall

SJASM and Amstrad CPC Development

Started by andymccall, 11:38, 08 April 24

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

andymccall

Hi,

I've started z80 assembler and have been going through the usual exercises of text output, loops, branching etc. etc. I've been producing binaries for the ZX Spectrum and Next.  My tool chain consists of Sublime, SJASMPlus and HDFMonkey for building images for the Next. I have started doing the same exercises for the Amstrad CPC using the same toolchain (minus hdfmonkey).  I wanted to try and stick to the same assembler if possible, but there are very few resources for Amstrad CPC development using sjasmplus and I'm generally a follow existing examples person rather than read pure text references and work out what I need to do from that.

My code isn't working and I'm not sure if it's either the assembly or the way I've compiled it into a snapshot, so I was hoping someone could point out what I'm doing wrong.  I think once I've got one of my examples working I should be able to look at other references to get the others working.
;----------------------------------
; AmstradCPC Char
;----------------------------------

device amstradcpc464


org $1200

;----------------------------------
; Program
;----------------------------------

stack_top:
    ld hl, string
    ld a,(hl)
    call $BB5A
    ret z

string defb 'H'                                                                 ; The Char to print

;----------------------------------
; Assembler output
;----------------------------------

DISPLAY ">----------------- Code Range           = ",/H,stack_top,"-",$
DISPLAY ">----------------- Code Length (Bytes)  = ",/D,$-stack_top
DISPLAY ">----------------- Code Space Remaining = ",/D,$c000-$

;----------------------------------
; Create a SNA file
;----------------------------------

savecpcsna "amstradcpcchar.sna", stack_top


This builds okay and produces an sna,

andymccall@raspberrypi4:~/programming/z80/amstradcpcchar$ sjasmplus --sld=amstradcpcchar.sld --lst=amstradcpcchar.lst --fullpath amstradcpcchar.z80
SjASMPlus Z80 Cross-Assembler v1.20.3 (https://github.com/z00m128/sjasmplus)
Pass 1 complete (0 errors)
Pass 2 complete (0 errors)
> >----------------- Code Range           = 0x1200-0x1209
> >----------------- Code Length (Bytes)  = 9
> >----------------- Code Space Remaining = 44535
Pass 3 complete
Errors: 0, warnings: 0, compiled: 34 lines, work time: 0.006 seconds


I know the assembler output probably isn't right at the moment as it's a straight copy from the ZX Spectrum code.  However when I load the snapshot using WinApe I get a corrupt character on my screen.



Please can someone point out where my mistakes are and help me get started on Amstrad CPC development in z80 using sjasmplus?

Thank you in advance!

andycadley

I suspect the snapshots it generates are very minimal, the CRTC registers are just set up with default values but none of the firmware is initialised etc. That sort of thing doesn't matter so much on a Spectrum, where system calls are in ROM but on a CPC you're calling a routine in RAM but the jump table hasn't been created and the lower routines aren't present in RAM.

Unless you're writing code that has no dependency on the system, you're probably better off creating a DSK file with the code in it and then doing a LOAD and CALL from BASIC, that way the system will be in a known good state.

genesis8

There are Amstrad CPC framework on linux (and certainly windows) to just do what Andy stated, but sorry no name pops in my mind at the moment. Check on Github though.

Are you on windows or linux ?
____________
Amstrad news site at Genesis8 Amstrad Page

andymccall

I'm using Linux, but I'm on a Raspberry Pi, so I need arm64 software, which is one of the reasons I wanted to continue using sjasmplus.

krusty_benediction

I have met plenty of issue when generating snapshot that make use of the firmware both with my assembler and rasm.
I guess they can be solved by injecting a snapshot that contains everything after booting a CPC.

Anyway, I see several issues in your code

- are you 100% sure that the assembler set PC to 1200 in the snapshot ? Other assemblers uses the directive RUN for that. edit: I guess it is the purpose of the last argument of the save command


stack_top:
    ld hl, string
    ld a,(hl)
    call $BB5A
    ret z

string defb 'H'   



you execute the code after ret z, that contains garbage.
it would be better to do ret z or jp z or whatever before calling bb5a


If you want to do tries with sna that manipulate firmware, maybe you should start with winape integrated assembler

krusty_benediction

with my assembler (basm .\test.asm --snapshot -o test.sna --override)

this works on dsk but not sna


;----------------------------------
; AmstradCPC Char
;----------------------------------
org $1200
run $
    breakpoint
;----------------------------------
; Program
;----------------------------------
stack_top:
    ld hl, string
    ld a,(hl)
    jp z, $
    call $BB5A
    inc hl
    jp stack_top    
string defb 'H'                                                                 ; The Char to print
;----------------------------------
; Assembler output
;----------------------------------
print ">----------------- Code Range           = ",{hex}stack_top,"-",$
print ">----------------- Code Length (Bytes)  = ",$-stack_top
print ">----------------- Code Space Remaining = ",$c000-$
save "test", stack_top, $-stack_top, DSK, "test.dsk"

andymccall

Okay, so I think I understand why it's not working from the SNA then.  The SNA doesn't contain all the information to fully set up the CPC for the way I want to use it, so using a dsk file would allow the emulator or system to be set up correctly, then I can load my file - is this correct?

It looks like this LUA package for SJASMPlus will let me produce a dsk file:

https://github.com/ClaireCheshireCat/dsk-lua

If I want to continue using sjasmplus, does this sound like I'm on the right path?

m_dr_m

Congrats for taking up Z80!

If you insist on cross dev, I recommend you rasm instead, which have very nice CPC-tailored features, but can also produce ZX snapshot.
BASM is Orgams-compatible, so that another great alternative!

krusty_benediction

Quote from: andymccall on 14:35, 08 April 24Okay, so I think I understand why it's not working from the SNA then.  The SNA doesn't contain all the information to fully set up the CPC for the way I want to use it, so using a dsk file would allow the emulator or system to be set up correctly, then I can load my file - is this correct?

It looks like this LUA package for SJASMPlus will let me produce a dsk file:

https://github.com/ClaireCheshireCat/dsk-lua

If I want to continue using sjasmplus, does this sound like I'm on the right path?
yep; seems good

another alternative, is to save binary files on disc with the appropriate amsdos header (no idea if it has to be manually build or if sjasm allows that) and drag and drop it on emulators accepting that (if ace does not, I'm sure it will do it if requested)

Prodatron

#9
Quote from: andymccall on 14:35, 08 April 24If I want to continue using sjasmplus, does this sound like I'm on the right path?

Hi @andymccall, welcome to the CPC world!
SJASMplus is indeed a powerful Z80 assembler and I can imagine, that you would like to stay with this one.

As far as I can see, you are currently using WinApe.

If you want to do some quick tests with SJAsmPlus + WinApe you could do it in this way:
- let SjAsmPlus assemble your source to a BIN file e.g. "c:\cpc\test.bin"
- in WinApe open the Assembler with F3 and just write

ORG #1200
RUN #1200
INCBIN"c:\cpc\test.bin"

Now press F9 in the WinApe assembler and it will be loaded directly into the emulator memory and executed.

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

Powered by SMFPacks Menu Editor Mod