Jump to content

Photo

Conversion of Z80 code to TMS9900


51 replies to this topic

#51 Asmusr ONLINE  

Asmusr

    River Patroller

  • Topic Starter
  • 2,335 posts
  • Location:Denmark

Posted Today, 3:02 PM

So what have I learned? It's definitely possible to convert Z80 code to the TI as can be seen here: http://atariage.com/...89-knight-lore/

 

My mapping of Z80 to TI register worked well:

tmp0   equ  0
tmp1   equ  1
one    equ  2
mone   equ  3
af     equ  4
a      equ  4
bc     equ  5
b      equ  5
c      equ  R5LB
de     equ  6
d      equ  6
e      equ  R6LB
hl     equ  7
h      equ  7
l      equ  R7LB
ix     equ  8
iy     equ  9
sp     equ  10
af_    equ  12
bc_    equ  13
de_    equ  14
hl_    equ  15

one and mone are constants 1 and -1 that I found that I used all the time.

 

It's inefficient to use the LSB registers c, e, and l because they have to be accessed as memory bytes rather than registers.

 

The Knight Lore code is checking the carry flag a lot. I found that after a byte compare (cp on Z80, cb on the TI) the carry condition on the Z80 correspond to JL on the TI or JHE for the inverse condition. If the carry flag is checked after a subtraction instead of a compare this has to be turned into a compare followed by a (possible) subtraction on the TI.

 

The biggest conversion issue is probably that loading data into a register (ld on Z80, mov or li on the TI) does not set any flags on the Z80, so here you can do a compare, then load something, and then check the condition. This type of code has to be reworked on the TI.

 

A stack and calls to subroutines can easily, but somewhat slowly, be emulated on the TI, but on the TI it's the called routine that pushes the return address (r11) onto the stack. IfZ80  code if jumping directly into subroutines (rather than calling) it is necessary to bypass the initial push of the return address on the TI.

 

Anyone has a commented Z80 disassembly of Elite?



#52 Asmusr ONLINE  

Asmusr

    River Patroller

  • Topic Starter
  • 2,335 posts
  • Location:Denmark

Posted Today, 4:03 PM

Forgot to mention: I believe converted code takes up 50% - 100% more memory than the Z80 code. Basically every Z80 instruction takes on byte and on the TMS9900 they take two. But it depends on the code and in this case the TMs9900 is a lot more efficient:

*
* =============== S U B R O U T I N E =======================================
*
* b: pixel Y
* c: pixel X
*
* Result in bc
*
calc_vidbuf_addr:
;RAM:D811 E5                          push    hl
;RAM:D812 CB 38                       srl     b                                       ; y >> 1, bit 0 to Carry
;RAM:D814 CB 19                       rr      c                                       ; Carry to bit 7, x >> 1
;RAM:D816 CB 38                       srl     b                                       ;
;RAM:D818 CB 19                       rr      c                                       ;
;RAM:D81A CB 38                       srl     b                                       ;
;RAM:D81C CB 19                       rr      c                                       ;
       srl  bc,3
;RAM:D81E 21 F3 D8                    ld      hl, #vidbuf                             ; bitmap buffer
;RAM:D821 09                          add     hl, bc                                  ; calculate bitmap memory address
;RAM:D822 4D                          ld      c, l
;RAM:D823 44                          ld      b, h                                    ; BC = bitmap memory address
       ai   bc,vidbuf
;RAM:D824 E1                          pop     hl
;RAM:D825 C9                          ret
       rt
*
* End of function calc_vidbuf_addr
*





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users