Write binary data to TRD from ASM

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

I'm also interested in this. Coincidentally I was reading around this earlier, and came across the following two snippets. Any use? They seem to describe two different ways of making TR-DOS calls.

Code: Select all

                ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ·
                º TR-Dos system functions. º
                ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ

The  system  functions  work  with file and logical level of
disk structure. The entry point for system functions call is
15635.  If  TR-Dos  is  not  initialized,  init.  subroutine
(15649)  must be called before system calls. Function number
is placed in C register.

ÖÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ·
º C   ³Function                                              º
ÇÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ
º Start of work with disk                                    º
º #00 ³Microcontroller reset                                 º
º #01 ³Read drive parameters. A=drive No. (0-3)              º
º #18 ³Read  disk parameters. 9th sector is read into buffer º
º     ³placed after TR-Dos variables                         º
º Logical level                                              º
º #05 ³Read sectors. HL=memory address, DE=start sector/trackº
º     ³B=number of sectors                                   º
º #06 ³Write sectors. Parameters are the same                º
º File level                                                 º
º #07 ³Write current disk catalog into stream (number in A)  º
º #08 ³Read catalogue entry (A=No.) into descriptor          º
º #09 ³Write catalogue entry from descriptor                 º
º #0A ³Find entry, placed in descriptor, in disk catalog.    º
º     ³#23814-number  of  bytes  to  match.  Returns:C=entry º
º     ³found, #FF, if no                                     º
º #0B ³Create  file.  HL=start  address, DE=length, name and º
º     ³type are in descriptor.                               º
º #0C ³Create BASIC-program (detailed previous function)     º
º #0E ³Read/verify  file.  #23801:#00-read, #FF-verify. Also º
º     ³can  be given: HL-start, DE-length. If A=0, start and º
º     ³length  are  taken from catalog, A=3 - only length is º
º     ³taken  from catalog, other cases - both HL and DE are º
º     ³significant.                                          º
º #12 ³Erase file. Name, type etc. are in descriptor.        º
º Service functions                                          º
º #13 ³Copy 16b from HL to descriptor                        º
º #14 ³Copy 16b from descriptor to HL                        º
º #17 ³Choose bottom disk side                               º
º #15 ³Test  physical track while formatting. Track is given º
º     ³in  D, side - with previous operation. 23766 - number º
º     ³of bad sectors on track                               º
ÓÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ
Other  functions  are  used  by  TR-Dos  and are useless for
programmer.

Other    themes:    TR-Dos    system   variables,   BetaDisk
microcontroller programming.
                 Igor Yudincev ([email protected])
                 Text is written in IS-Editor v.1.1, 1.06.97

Code: Select all

15   MACHINE CODE PROGRAMMING

The inclusion of TRDOS  routines  in  machine  code  programs  are
relativey straightforward.

There are 3 elements required for the program:

(1) The machine code equivalent of the BASIC TRDOS command.
(2) The machine code routine to implement 1 above.
(3) The machine code routine to restore the system to its original
    state before calling and executing the command.

The actual memory locations used will depend upon the program as a
whole. For the  purpose  of  this  example  the  location  of  the
routines  will be at 49000 for the SAVE, at 49500 for the LOAD and
at 50000 for the instructions calling them. Thus item 1 will be at
either 49000 or 49500 and items 2 and 3 at 50000.

EXAMPLE:

Address     Code     Basic   Comment

49000       234      REM     Codes as in Appx A of Spectrum
49001        58       :      manual
49002       248      SAVE
49003        34       "
49004        69       E
49005       120       x
49006        97       a
49007       109       m      File name "Example"
49008       112       p
49009       108       l
49010       101       e
49011        34       "
49012        13      ENTER   Always end with ENTER

The  code for the LOAD commences at  49500 and is eaxctly the same
as above except that address 49502 will contain 239 (LOAD) instead
of 248 (SAVE).

These two  routines, LOAD, and  SAVE can be  located anywhere, but
the  initiator which we are locating at 50000 requires changing at
addresses  50007-50008 (Save  routine address)  and 50025  - 50026
(LOAD routine address) to point to the new addresses.

To relocate, the  initiator itself  requires reassembly.  For that
reason the Z80 mnemonics only are given below.

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

The whole routine  pointing to  both the  SAVE and  LOAD routines,
together with the  "return  to  point  of  entry"  ending  routine
occupies only 47 bytes.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Write binary data to TRD from ASM

Post by Ralf »

Maybe try posting to zx.pk.ru I suppose it's the best place to get the answer. It's Russian forum but they have an English section if I remember correctly.
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 »

My bad. Overall I've adapted that example from the book, 'ZX-Spectrum & TR-DOS Для пользователей и программистов' page 194. However, it looks like I've made a number of mistakes while doing that:

1. The '#00: load, #FF: save' comment is indeed wrong and should read '#FF: verify' instead. Saving is done with another function (C=#0B).

2. The input value in A is decoded as:
A = 0: loads the file using the default loading address and length defined at save time.
A = 3: assumes HL = loading address, and DE = length.
A = Any other value: assumes HL = loading address and uses the default length defined at save time.

3. There's actually a point to the CALL: RET construction at the end because otherwise this routine might not work from BASIC (the TR-DOS ROM would still be switched on at the time of return).

The corrected example for loading a file in TR-DOS to a custom address should therefore read as follows:

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
	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

Now for saving files. This will check if a file with a given name exists, delete it if it does, and save the file. Notice that the file isn't physically deleted but only 'marked as' deleted, which is the same as doing an ERASE in TR-DOS prompt. In case it was not the last file on the disk, it might be necessary to issue a MOVE in TR-DOS prompt in order to make sure this disk space isn't 'lost touch with'.

Code: Select all

SaveExample
	ld hl,FileDescriptor
	ld c,#13		;copy the file descriptor to TR-DOS system variables
	call #3D13
	ld a,9			;find a file with matching 9 first bytes in the descriptor, i.e. just the filename and type
	ld (#5D06),a
	ld c,#0A
	call #3D13
	inc c			;C will contain #FF if the file with this name wasn't found
	ld c,#12		;if it was found, mark the file descriptor as deleted
	call nz,#3D13
	ld hl,Address		;save the file
	ld de,Length
	ld c,#0B
	call #3D13
	ret

FileDescriptor
	DEFB "FILENAME"		;8 characters
	DEFB "C"		;file type: code
One more thing: it is typically advised to set IY to #5C3A before calling any sort of system/ROM functions.

Hope this helps.
Inactive account
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

keith56 wrote: Fri Dec 08, 2017 9:54 amTRDos changed their specification between ver 4 and 5, and commands all changed, with "RANDOMIZE USR 15360" changed to "RANDOMIZE USR 15616"
How do you write code that works on all versions? Or do you just assume that everyone is running v5 now?
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

keith56 wrote: Fri Dec 08, 2017 9:54 amI'm building my trd files with trdtool, which is great, butI'm wondering if the files its making are not quite right, as I seem to be having a lot of trouble.

https://shiru.untergrund.net/software.shtml
I found this too, and it's working nicely. Shiru's stuff is great.

How are you creating your Basic boot file? trdtool takes a tokenized file not an ascii file. This stumped me for a while, then I used bas2tap to tokenize it, and tzx_display to extract the headerless program block from the tap.

Is there a more straightforward way to do this?
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
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 »

keith56 wrote: Fri Dec 08, 2017 9:54 am But then again I had a lot of trouble in the early days becaue TRDos changed their specification between ver 4 and 5, and commands all changed, with "RANDOMIZE USR 15360" changed to "RANDOMIZE USR 15616" causing many of the samples of source-code I found could not work..
I believe it is entirely safe to ignore any versions below 5.03. v5.01 has seen some usage in the 90's around here in Russia/CIS but was quickly replaced by v5.03. If you're keeping to documented entry points such as #3D13 then they are compatible and should behave identically.
Inactive account
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 »

keith56 wrote: Sat Dec 09, 2017 12:32 amout of interest, what is the best rom to use for testing (compatibility wise?)
Well, the original 5.03 is considered the baseline version of sorts. This is the last known official release. Another widespread edition is the unofficial 5.04T, which comes as the default ROM in some major 'Pentagon'-oriented emulators, most notably UnrealSpeccy. As far as I know, this is mostly unchanged 5.03 with several bugs fixed by enthusiasts. It's probably a good idea to target either one of those.
There were subsequent unofficial bugfix editions and mods, but they are less known.

I've uploaded a commented disassembly of 5.04T by Pavel Fedin and Spectre here. I find this useful to refer to when I don't understand what's going wrong. The commentary is in Russian, but I believe googletranslate should do a reasonable job with it.
Inactive account
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

Hi [mention="Hikaru"]Hikaru[/mention], 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 :)
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Write binary data to TRD from ASM

Post by Ast A. Moore »

Psst, [mention]Seven.FFF[/mention]. Boing.
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: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

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.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Write binary data to TRD from ASM

Post by Ast A. Moore »

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.
[mention]Seven.FFF[/mention]
You just don’t know how to cook it. Chapter 24. ;)
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: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

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!
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

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.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Write binary data to TRD from ASM

Post by Ast A. Moore »

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.
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 »

Seven.FFF wrote: Mon Dec 11, 2017 2:19 pm Hi [mention="Hikaru"]Hikaru[/mention], 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.
Inactive account
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

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.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

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.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
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 »

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 [mention]keith56[/mention] 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. :)
Inactive account
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Write binary data to TRD from ASM

Post by Ast A. Moore »

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
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: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

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

Will write a longer reply later.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

Hikaru wrote: Tue Dec 12, 2017 1:03 pm 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.
Awesome, thanks. I will get there eventually. Somehow it's harder integrating new info in a foreign language until you reach a tipping point. I don't know how you multilingual guys do it, but you rock.
Hikaru wrote: Tue Dec 12, 2017 1:03 pm 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.
You're right. This is code that's I copied and pasted between projects, and somehow I have strayed away from the original intention - which was to set up the environment in a deterministic state after external loaders (mostly DivMMC/exsDOS) have dumped you into the starting point. Clearly I'm not doing what I intended here!
Hikaru wrote: Tue Dec 12, 2017 1:03 pm 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. :)
Thanks! I have had help I'm afraid. Mikhail Sudakov (Castlevania Spectral Interlude) kindly offered to help with translations. He already warned me about context and word-ending changes. I woke up to the same message from him as I did from you!! Обнулить таблицу рекордов was too long - and I just now saw that he gave me Обнулить рекорды as an alternative right from the beginning :D
Ast A. Moore wrote: Tue Dec 12, 2017 1:46 pm 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.”
Another piece of the puzzle, cheers :)
Ast A. Moore wrote: Tue Dec 12, 2017 1:46 pm Then there’s the manual for BETA 128 interface itself, which isn’t particularly useful, but has a little assembly snippet nevertheless.
I had been trying to get this one working too. This is the "official" API that passes tokenized basic commands to TR-Dos. I ran into issues with my tokenization - the stuff in my reference REM statements were being tokenised as "C", "O", "D", "E" etc and it was causing confusion with some other problems I was having at the same time. It clearly works in my basic loader though, so I could revisit this later. But I don't really need to.

I now have an asm loader that loads everything except $6000-$7FFF (and updates my progress bar). Loading this block is breaking TR-Dos, so I need to debug to see what's going on. I don't really want to rearchitect the game because the codebase is shared with the non-Pentagon version (and space in unpageable RAM is TIGHT!!), so I will have to figure out a way to have code from $6000-> and stack from <-$5FFF, and still keep Dos working well enough to save my high scores every game end. Also I'm using the ZX Printer buffer as a general purpose buffer in a ton of places, so will need to figure out something different there.

Are there any special Pentagon-only horizontal MMU schemes that would help, by any chance? Mostly a rehetorical question - I have lots of reading to do... :)
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Write binary data to TRD from ASM

Post by Ast A. Moore »

Something interesting for you to investigate. This version of Battle Command has an unusual loader. It displays a scrolling text and plays music while loading the game. Might be worth reverse engineering.
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 »

Seven.FFF wrote: Wed Dec 13, 2017 7:39 pm I now have an asm loader that loads everything except $6000-$7FFF (and updates my progress bar). Loading this block is breaking TR-Dos, so I need to debug to see what's going on. I don't really want to rearchitect the game because the codebase is shared with the non-Pentagon version (and space in unpageable RAM is TIGHT!!), so I will have to figure out a way to have code from $6000-> and stack from <-$5FFF, and still keep Dos working well enough to save my high scores every game end. Also I'm using the ZX Printer buffer as a general purpose buffer in a ton of places, so will need to figure out something different there.
File level operations use a temporary extra buffer of about 256 bytes that is located after the regular TR-DOS variables (110-something bytes). Any BASIC data in the area gets temporarily saved higher in the memory. So I'd suggest you to clear the BASIC part of your loader first. 24576 doesn't seem that low in the memory, so that might just be enough to make it work.

I think this should do the trick, but don't take my word for it. :)

Code: Select all

ClearBasic
	ld hl,(#5C59)		;E-LINE: end-marker of the current variables area - the '80-byte'
	ld de,(#5C53)		;start of BASIC program area
	dec hl
	call #19E5		;RECLAIM-1
Inactive account
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Write binary data to TRD from ASM

Post by Seven.FFF »

Still messing around with this. I had several errors in how I was saving my binary chunks and also how I was loading them. No wonder it wasn't working. Hopefully will have time to finish debugging this weekend. Thanks [mention]Hikaru[/mention].

In the meantime I knocked up a repeating attract thingy on the menu. Amazingly I managed to get it locked to the alien timings so it doesn't drift out of sync. It's a bit jerky cos I don't have a good gif grabber that works with Pentagon timings.

Image
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Write binary data to TRD from ASM

Post by Ast A. Moore »

Seven.FFF wrote: Sat Dec 16, 2017 2:33 am It's a bit jerky cos I don't have a good gif grabber that works with Pentagon timings.
Fuse > fmfconv (Fuse utilities), maybe?

The menu looks splendid, by the way. Love the proportional font.
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.
Post Reply