Jump to content

Photo

Conversion of Z80 code to TMS9900


58 replies to this topic

#51 Asmusr OFFLINE  

Asmusr

    River Patroller

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

Posted Thu Jul 20, 2017 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. If Z80 code is 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 OFFLINE  

Asmusr

    River Patroller

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

Posted Thu Jul 20, 2017 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 one 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
*


#53 artrag OFFLINE  

artrag

    Dragonstomper

  • 704 posts

Posted Thu Jul 20, 2017 11:43 PM

 
Anyone has a commented Z80 disassembly of Elite?

I can point you to the commented sources of Uridium (there is an improved version for cv) an of Tales of Popolon (a 3D fps on msx)

https://youtu.be/xaNX8i5f4pc

Edited by artrag, Fri Jul 21, 2017 1:11 AM.


#54 apersson850 OFFLINE  

apersson850

    Moonsweeper

  • 421 posts

Posted Fri Jul 21, 2017 1:18 AM

When you simply convert code, that's written to work well on one CPU, to another, that's quite a lot different, you have to count on that the code will not be that terrific when translated. But if you re-write it to actually exploit the advantages of that second architecture, then it may be even better (depending on the source and target systems, of course).



#55 artrag OFFLINE  

artrag

    Dragonstomper

  • 704 posts

Posted Fri Jul 21, 2017 6:14 AM

Given that the vdp is the same it is matter of rewriting the same loops and algorithms for the new cpu
You can start transposing opcode by opcode and then optimise once the loop starts running

Edited by artrag, Fri Jul 21, 2017 11:18 AM.


#56 Asmusr OFFLINE  

Asmusr

    River Patroller

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

Posted Fri Jul 21, 2017 6:36 AM

I can point you to the commented sources of Uridium (there is an improved version for cv) an of Tales of Popolon (a 3D fps on msx)

 

Do you think anything in Uridium would benefit from a 16-bit architecture or would it end up running at half speed?



#57 artrag OFFLINE  

artrag

    Dragonstomper

  • 704 posts

Posted Fri Jul 21, 2017 7:31 AM

All the x coordinates of the objects are 16 bit, if not 24 bits (due to decimal parts). Some of the y coordinates are 16 bits to take into account decimal points. How fast the TMS9900 is in doing a large case/switch and in doing 8 and 16bit comparisons?

Anyway, in case of problems, one can reduce the max number of enemies or set the speed at 30 fps.

Both aspects are already implemented, one by a label, the other in the menu where there is the choice of the difficulty level, where easier modes work slowing down the main loop by adding extra waiting for vblank.


Edited by artrag, Fri Jul 21, 2017 1:12 PM.


#58 Asmusr OFFLINE  

Asmusr

    River Patroller

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

Posted Sat Jul 22, 2017 12:33 PM

How fast the TMS9900 is in doing a large case/switch and in doing 8 and 16bit comparisons?

 

A large case/switch is just a jump table I guess? 8 and 16 bit comparisons (CB and C) are equally fast, but I don't know how fast they are compared to the Z80.



#59 artrag OFFLINE  

artrag

    Dragonstomper

  • 704 posts

Posted Sat Jul 22, 2017 2:56 PM

 
A large case/switch is just a jump table I guess? 8 and 16 bit comparisons (CB and C) are equally fast, but I don't know how fast they are compared to the Z80.

Yes,the switches are used in the enemies and in the collisions
About the relative speed, maybe one can eventually compensate by using less enemies or setting at 30hz the frame rate

Edited by artrag, Sat Jul 22, 2017 3:41 PM.





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users