Weird programming in Roms?

Everything about programming, including VDP and Sound programming.
Post Reply
User avatar
Crazyboss
Site Admin
Posts: 274
Joined: 09 Aug 2012 21:45
Location: Sweden
Contact:

Weird programming in Roms?

Post by Crazyboss »

Hi.

I was wondering if any one have analyzed the code in the Roms of the Memotech Computer. I asked Andy some years ago, if he discovered any diffirence between the code in the Roms, as I remember he said there was no diffirences in the roms, so I guess the Roms was more or less bugfree, and Memotech did not have to change anything.

They patched the roms with hardware, for other countries like Danish, Finish etc by Like solder an extra rom chip on the exsisting one in the Computer.

I was also wondering have seen some weird code, like code that could be optimized, or some very clever optimized code we could learn from ? Back in those days, a lot of dirty tricks was used, and it was quite common, to do somethin that was not good programming, but it got the job done, and even faster than make good clean code. Thats why some dissassemblers get confused sometimes, when looking at that code. It was also very common in Arcade games. I was told there also was put in traps in Arcade games, not sure why maybe to foul others with the code so they didn steal the code. I an Colecovision game I saw something, where they detect if the game is running in RAM, if so the game overwrites itself and crash. I guess that was to prevent ColecoVIsion games to be copied to Disk/Tapes and run on the Adam in CP/M. But if you know how to transfer a Cartrigde to Disk, you might also know how to remove that check ;)
//CLAUS - Webmaster at www.mtxworld.dk
Martin A
Posts: 799
Joined: 09 Nov 2013 21:03

Re: Weird programming in Roms?

Post by Martin A »

There's a few "Quirks" I know of :

The most famous one is "Hello Caro" embedded into the Assembler. Pulled here from the re-build of the source.

Code: Select all

2BD0                        .sectable
2BD0        48 65 6C 6C 6F 
            20              DB   &48,&65,&6C,&6C,&6F,&20
2BD6        43 61 72 6F     DB   &43,&61,&72,&6F
2BDA                        
2BDA                        .flagtable
Sectable probably means secret table I guess.

There's also a typo in the error message output routine that got missed and ended up having a workaround added.

Code: Select all

18FB                        .synt11
18FB        F5              PUSH AF
18FC        D7              RST  &10      ; output routine
18FD        6F              DB   &6F      ; select VS7 and clear
18FE        0D              DB   &0D      ; send 13 to the screen note no continuation bit
18FF        0A              DB   &0a      ; decoded as instruction LD A,(BC)
1900        21 13 19        LD   HL,err0
1903        F1              POP  AF
1904        CD DD 19        CALL find
1907                        .outstr
If the DB &0D had been coded as DB &2D as it should have been, the surrounding PUSH AF/POP AF wouldn't have been needed. And 2 bytes would have been saved. Of course the VS7 error window being a single line, the line feed isn't needed anyway, CLS and CR does the job. Making a potential 3 byte saving.

Here's how CR/LF is encoded in the newline routine elsewhere.

Code: Select all

001B                        .newline
001B        D7              RST  &10      ; output routine
001C        2D              DB   &2D      ; send 13 to the screen
001D        0A              DB   &0A      ; send 10 to the screen
001E        C9              RET
Ever wondered why OUT 1000,10 or even OUT 66666,66666 works but PRINT INP(1000) returns the out of range error??

The code for OUT

Code: Select all

09FA        02              DB   &02
09FB        2C              DB   &2C
09FC        02              DB   &02
09FD                        .sout
09FD        F7              RST  &30         ; fetch the address 
09FE        C5              PUSH BC          ; save it
09FF        F7              RST  &30         ; fetch the data
0A00        C1              POP  BC          ; get the address back
0A01        ED 79           OUT  (C),A       ; do the port access
0A03        C9              RET
There is no range checking, RST &30 returns a 16 bit integer in BC and also sets A equal to C, so the 16 bit port address is accepted, and the data just the value modulo 256.

The INP function on the other hand calls for a small value address and exits with the out of range (via out112) of the top byte isn't zero

Code: Select all

309                        .inp
1309        CD BB 11        CALL smallen
130C        20 F5           JR   NZ,out112
130E        4F              LD   C,A
130F        ED 78           IN   A,(C)

More space could have been saved by not doing the range check and allowing 16 bit input ports.
Post Reply