Write binary data to TRD from ASM

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
Ast A. Moore
Manic Miner
Posts: 717
Joined: Mon Nov 13, 2017 3:16 pm

Re: Write binary data to TRD from ASM

Post by Ast A. Moore » Mon Dec 11, 2017 2:54 pm

Seven.FFF wrote:
Mon Dec 11, 2017 2:46 pm
Ha, thanks! That's the one I have. I translated the TOC (and the first 20 pages), and I think there is nothing about TR-Dos at all in this book. Even the cover says "ZX Spectrum for users and programmers, no mention of TR-Dos.
@Seven.FFF
You just don’t know how to cook it. Chapter 24. ;)
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Seven.FFF
Manic Miner
Posts: 283
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF » Mon Dec 11, 2017 2:58 pm

Yay that's it, thanks.

He wrote two different books, ISBN 5-7190-0025-9 (Spectrum and TR-Dos) and 5-87472-004-9 (just Spectrum). The online text is on your link is correct, but the download is linked to the wrong book, ha.

Ta!
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

User avatar
Seven.FFF
Manic Miner
Posts: 283
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF » Mon Dec 11, 2017 3:00 pm

Anyway my asm calls aren't working, even Hikaru's reference asm load example. My basic calls work fine. At work now but I will try and debug later.
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

User avatar
Ast A. Moore
Manic Miner
Posts: 717
Joined: Mon Nov 13, 2017 3:16 pm

Re: Write binary data to TRD from ASM

Post by Ast A. Moore » Mon Dec 11, 2017 3:31 pm

Seven.FFF wrote:
Mon Dec 11, 2017 2:58 pm
The online text is on your link is correct, but the download is linked to the wrong book, ha.
Whoopsie. Didn’t notice the download link at all.
Seven.FFF wrote:
Mon Dec 11, 2017 3:00 pm
Anyway my asm calls aren't working, even Hikaru's reference asm load example. My basic calls work fine.
Mating calls of other species are notoriously difficult to master. Many have tried. Many have failed.
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

Hikaru
Microbot
Posts: 100
Joined: Mon Nov 13, 2017 1:42 pm
Location: Russia
Contact:

Re: Write binary data to TRD from ASM

Post by Hikaru » Mon Dec 11, 2017 6:05 pm

Seven.FFF wrote:
Mon Dec 11, 2017 2:19 pm
Hi @Hikaru, I wonder if you could link me to your copy of 'ZX-Spectrum & TR-DOS Для пользователей и программистов', if you have it as a scan. The one I have only goes up to page 114. It's either a different book or it's missing all the good stuff :)
Heys. This is the scanned version that I'm using. But it's in .DJVU format, not sure if that's useful for google translate and whatnot. Like Ast said, it should be available to read online at zxpress.ru as well, although their OCR quality tends to leave much to be desired.

Seven.FFF wrote:
Mon Dec 11, 2017 3:00 pm
Anyway my asm calls aren't working, even Hikaru's reference asm load example. My basic calls work fine. At work now but I will try and debug later.
One reason might be because, as a general rule, code like that or similar using #3D13 functions is intended to execute after the DOS is fully initialized, for instance as part of a loader. So for instance if you just run it from a snapshot, it is very likely not going to work.

Actually, this is something I'd like to know myself, because there's supposedly an 'init' function located at 15649 that is responsible for initializing the TR-DOS system variables (mentioned at p.190), but I've never had any success with it alone. Perhaps it needs something else besides that.
0 x
Inactive account

User avatar
Seven.FFF
Manic Miner
Posts: 283
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF » Tue Dec 12, 2017 1:01 am

I've made a little progress. The error returned in $5D0F was 1 No file. i wasn't padding my filename with spaces in the file descriptor.

Now I get error 12 The channel is not open in $5D0F. But I have already been using TR-DOS - the code this is running from is loaded from basic with a TR-Dos call, so Dos must be initialised, surely?

My (rather chunky) basic loader looks like this:

Code: Select all

10 CLEAR 32767: BORDER 0: PAPER 0: INK 7: BRIGHT 1: FLASH 0: CLS 
20 PRINT AT 7,9; INK 2;"j"; INK 6;"e"; INK 3;"t"; INK 5;" p"; INK 2;"o"; INK 4;"w"; INK 3;"e"; INK 6;"r "; INK 3;"j"; INK 5;"a"; INK 6;"c"; INK 4;"k"; INK 7;AT 10,12;"LOADING..";AT 12,11;"3ArPy3KA...": PLOT 106,77: PLOT 106,78: DRAW 4,0: PLOT INVERSE 1;107,77: DRAW INVERSE 1;2,0: PLOT 121,78: PLOT 125,78: PLOT INVERSE 1;121,75: DRAW 3,0: PLOT INVERSE 1,122,74: DRAW INVERSE 1;2,0
30 RANDOMIZE USR 15619: REM :LOAD "jpj04" CODE 32768
40 RANDOMIZE USR 32768: RANDOMIZE USR 15619: REM :LOAD "jpj01" CODE 32768 
50 RANDOMIZE USR 15619: REM :LOAD "jpj02" CODE 56323
60 RANDOMIZE USR 15619: REM :LOAD "jpj03" CODE 65380
70 RANDOMIZE USR 32768
Nothing here loads any lower than $8000 [actually my stack is just below $8000, but surely it doesn't go down far enough to cause a problem with TR-Dos?], and it all gets loaded and runs fine.

Part of the code in jpj01 is my asm loader, which ends up at $AA00 and looks like this:

Code: Select all

                        di
                        ld hl, FileDescriptor
                        ld c, $13                       ; #3D13 C=#13: copy the file descriptor to TR-DOS system variables
                        call $3D13
                        di
                        xor a
                        ld ($5CF9), a                   ; #00: load, #FF: verify
                        dec a                           ; load the file to an address in HL
                        ld hl, $8000
                        ld c, $0E
                        call $3D13                      ; #3D13 C=#0E: load/save file
                        ei
                        ld a, ($5D0F)                   ; TR-Dos error is reported back here as "12 The channel is not open"
                        jp $8000                        ; This is supposed to be the code in jpj06. But it never gets loaded here.
FileDescriptor:
                        db "jpj06   "                   ; 8 characters
                        db "C"                          ; file type: code
I’m in IM 1 when it runs, and I’ve tried it with interrupts both enabled and disabled. I made sure it was in unpageable memory in case something was getting switched out unexpectedly.

The code in jpj06 is just a trivial test designed to be highly visible.

Code: Select all

BorderTest:             ld a, 2
                        out ($FE), a                    ; Magenta border
                        ld a, 5                         ; then
                        out ($FE), a                    ; Cyan border
                        jp BorderTest                   ; forever...
                                                        ; Actually this needs to be jr BorderTest, because I relocate the code,
                                                        ; but it's moot because it never gets loaded :(
This is my sadface TRD image. The failing loader runs when you hit the 0 key on the menu. Pentagon 128 only - the multicolour timings don’t work with Scorpion.

Any idea at all what gives?
Last edited by Seven.FFF on Tue Dec 12, 2017 2:21 am, edited 5 times in total.
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

User avatar
Seven.FFF
Manic Miner
Posts: 283
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF » Tue Dec 12, 2017 1:17 am

Hikaru wrote:
Mon Dec 11, 2017 6:05 pm
Heys. This is the scanned version that I'm using. But it's in .DJVU format, not sure if that's useful for google translate and whatnot. Like Ast said, it should be available to read online at zxpress.ru as well, although their OCR quality tends to leave much to be desired.
THanks, perfect! Now I can read the code cleanly at least.

I tried OCRing a few pages with Tesseract high-quality Russian training data, and the results were not great either. I think it needs special training for that font.
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

Hikaru
Microbot
Posts: 100
Joined: Mon Nov 13, 2017 1:42 pm
Location: Russia
Contact:

Re: Write binary data to TRD from ASM

Post by Hikaru » Tue Dec 12, 2017 1:03 pm

Seven.FFF wrote:
Tue Dec 12, 2017 1:01 am
I've made a little progress. The error returned in $5D0F was 1 No file. i wasn't padding my filename with spaces in the file descriptor.

Now I get error 12 The channel is not open in $5D0F. But I have already been using TR-DOS - the code this is running from is loaded from basic with a TR-Dos call, so Dos must be initialised, surely?
Meh. It fails since it's actually doing a 'verify' operation - because guess what, there are actually two variables responsible for this, the second one being #5D10. Neither Rodionov's book nor the disassembly mention that one (I don't even see it listed as a TR-DOS variable), although it's possible to trace where the check occurs in the disassembly.
It looks like @keith56 has figured this out on his own previously, since both #5CF9 and #5D10 are being set up in his code.

With this in mind, the loader example finally becomes:

Code: Select all

LoadExample
	ld hl,FileDescriptor
	ld c,#13		;#3D13 C=#13: copy the file descriptor to TR-DOS system variables
	call #3D13
	xor a
	ld (#5CF9),a		;#00: load, #FF: verify
	ld (#5D10),a
	dec a			;load the file to an address in HL
	ld hl,MyAddress
	ld c,#0E
	call #3D13		;#3D13 C=#0E: load/save file
	ret

FileDescriptor
	DEFB "FILENAME"		;8 characters
	DEFB "C"		;file type: code
Fingers crossed! xD

On a bit unrelated note,
1. OUTputting a random value from #5B5C to (#7FFD) at the start of your main code and hoping for the best isn't exactly a good idea. There's no telling which ROM/screen/page that would activate, or indeed whether you won't be screwed the next time an IM1 interrupt comes. It's better to set both of them to a known value of your own if you have to.
2. The correct spelling for the last option is 'Обнулить рекорды' (or 'Обнуление рекордов'). Regardless that's pretty cool I think, you don't often see people translating their games to Russian on their own. :)
0 x
Inactive account

User avatar
Ast A. Moore
Manic Miner
Posts: 717
Joined: Mon Nov 13, 2017 3:16 pm

Re: Write binary data to TRD from ASM

Post by Ast A. Moore » Tue Dec 12, 2017 1:46 pm

Hikaru wrote:
Tue Dec 12, 2017 1:03 pm
Neither Rodionov's book nor the disassembly mention that one (I don't even see it listed as a TR-DOS variable), although it's possible to trace where the check occurs in the disassembly.
Well, there’s this, which describes the variable at #5d10 as “MSB of TR-DOS error code, cleared on 15616 calling, should be cleared when you call 15635.”

Then there’s the manual for BETA 128 interface itself, which isn’t particularly useful, but has a little assembly snippet nevertheless.

Code: Select all

CHADD  EQU   23645         Location of SOS variable CHADD
       ORG   XXXXX         XXXX=address of this code
       LD    HL,(CHADD)    Start to save true CHADD
       LD    (TEMP), HL    Temporary store of true CHADD
       LD    HL,49000      Address of SAVE routine
       LD    (CHADD),HL    CHADD now points to our routine
       CALL  15363         ENTER TRDOS SAVE via chadd
       JP    BACK          Jump to program point from which
                           the whole routine was called
       LD    HL,(CHADD)    
       LD    (TEMP),HL     The routine for LOAD now repeats
       LD    HL,49500      the above with just the address
       LD    (CHADD),HL    changed.
       CALL  15363         
BACK   LD    HL,(TEMP)     Start to restore CHADD
       LD    (CHADD),HL    Reload original CHADD
       RET                 Return from where you came
TEMP                       Label allocating memory for
                           temporary storage
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Seven.FFF
Manic Miner
Posts: 283
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF » Tue Dec 12, 2017 3:43 pm

Yay, ld (#5D10),a makes it work! Cheers guys :)

Will write a longer reply later.
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

Post Reply