z00m128 / sjasmplus

Command-line cross-compiler of assembly language for Z80 CPU.
http://z00m128.github.io/sjasmplus/
BSD 3-Clause "New" or "Revised" License
383 stars 54 forks source link

Multiple ORG directives silently ignored? #209

Closed vampirehunt2 closed 1 year ago

vampirehunt2 commented 1 year ago

Hello, I am switching from a different z80 assembler, where this code worked: `org 0000h LD SP, RAMTOP ; initialise stack pointer to the top of available RAM IM 2 ; set interupt mode to 2 LD A, 01h ; higher byte of the interrupt vector table LD I, A ; set the vector table address ;CALL copyRom2Ram EI ; enable interrupts CALL resetNmiHandler JP boot ; jump over the interrupt handlers for NMI and mode 1 INT

org 0020h Version: defb 0, 0, 0, 0 Build: defw 0000h

org 0038h ; respond to mode 1 interrupt EX AF, AF'
EXX CALL handleInt EXX EX AF, AF'
EI RETI

org 0066h ; NMI handler PUSH AF CALL handleNmi CALL customNmiHandler POP AF EI RETN

; rest of the code goes here `

Essentially, puts the interrupt handling routines where they should be and then the rest of the code follows after that. However, sjasmplus does not seem to recognise this, for example, address $0020 does not contain the value 0 as defined by defb in the assembled binary file. Is there a way to get the required behaviour without having to manually count bytes?

ped7g commented 1 year ago

yes, you should never count bytes manually.

sjasmplus has two main modes:

a) raw output (--raw or OUTPUT), where ORG does affect how label values are assigned and jumps/calls calculated, but padding bytes must be emitted, for example with DS:

  ORG 0
  ; rst 0x00 handler
  di
  ;..
  DS 0x20-$, 0 ; output nops (value 0) until address 0x20
  ; rst 0x20 handler
  ret
  DS 0x66-$, 0 ; nops until 0x66
  ; rst 0x66 handler
  retn

b) virtual device mode, where ORG does redirect following assembling to desired address, and you can save "current" state of virtual memory by SAVEBIN/SAVEDEV/SAVESNA/SAVETAP/... directives, ie.:

  DEVICE AMSTRADCPC6128
  ORG 0x00
  di
  ;...
  ORG 0x20
  ; ...
  ORG 0x66
  ; ...
  SAVEBIN "code.bin", 0x0000, 0x400  ; without 0x38 handler below (!)
  ORG 0x38
  di
  ; ...
  SAVEBIN "code38.bin",0x0000,0x400 ; current memory -> this file contains also 0x38 handler
vampirehunt2 commented 1 year ago

Thank you!