translated document of optimized graphics routines

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
andydansby
Microbot
Posts: 148
Joined: Fri Nov 24, 2017 5:09 pm
Location: Syracuse, NY, USA
Contact:

translated document of optimized graphics routines

Post by andydansby »

While learning about different assembler techniques, I occasionally come across various Russian articles. One in particular caught my interest at https://zxpress.ru/article.php?id=5429. The problem using Google translate is the odd wording that be a result of the process. This can occur especially when words are broken and a general result of off translations. Technical terms and slang will also throw off a translation.

So what I have done should be a better translation of the above document to English.

The article is an optimization of some of the code presented in the book - 40 Best Machine Code Routines for the ZX Spectrum by John Hardman and Andrew Hewson .

None of this code is mine and I did not write the article, I'm just doing a translation of the document. I have an Open office document of this as well as a PDF. I have also included a .ASM file that I created with ZX Assembler.

The link is https://1drv.ms/f/s!Atc34t6eCvqj2kRv9PT ... f?e=wefdd9.

I can not make any guarantees on how long Onedrive will keep this link available.

enjoy
Andy Dansby
User avatar
Einar Saukas
Bugaboo
Posts: 3145
Joined: Wed Nov 15, 2017 2:48 pm

Re: translated document of optimized graphics routines

Post by Einar Saukas »

Good work!

Notice there's still considerable room for improvement in these routines. Not surprising, considering this article was written over 25 years ago...

For instance:

Code: Select all

; ;-------------------------------------------
; ;Shift attributes to the right
; ;-------------------------------------------
ASRL_RG:
         LD      DE,#5AFF      ; address of the last attribute byte
LP_ASRG: LD      H,D           ; ;copied DE to HL -
         LD      L,E           ; last byte of the attribute line
         DEC     HL            ; last byte of the attribute line
         LD      BC,#001F      ; <attribute line length> - 1
         LDDR                  ; shift the attribute line to the right
         LD      A,(CONSTS)    ; fill color after shift
         LD      (DE),A        ; set a new attribute
         DEC     DE            ; go to next line from top
         BIT     3,D           ; if we are still in attributes,
         JR      NZ, LP_ASRG   ; then we repeat the cycle for the next one. lines
         RET                   ; exit procedure
It can be rearranged as follows:

Code: Select all

; ;-------------------------------------------
; ;Shift attributes to the right
; ;-------------------------------------------
ASRL_RG:
         LD      A,(CONSTS)    ; color to be filled after shift
         LD      DE,#5AFF      ; address of the last attribute byte
         LD      H,D           ; ;copied DE to HL -
         LD      L,E           ; last byte of the attribute line
LP_ASRG: DEC     HL            ; last byte of the attribute line
         LD      BC,#001F      ; <attribute line length> - 1
         LDDR                  ; shift the attribute line to the right
         LD      (DE),A        ; set a new attribute
         DEC     DE            ; go to next line from top
         BIT     3,D           ; if we are still in attributes,
         JR      NZ, LP_ASRG   ; then we repeat the cycle for the next one. lines
         RET                   ; exit procedure
There's no need to spend time copying DE to HL every time when they are already identical (the same mistake happens in most routines).

Also there's no need to reload A every time since it never changes.
SamC
Microbot
Posts: 168
Joined: Sun Sep 29, 2019 9:07 pm

Re: translated document of optimized graphics routines

Post by SamC »

Maybe just as a curiosity, when asm graphics is mentioned here: In the eighties 3D routines for ZX Spectrum were published in the Czechoslovakian magazine "Amaterske radio" (5 pages).
In the next article, the code was sped up considerably (4 pages).
The third article is about drawing an ellipse (2 pages).

https://sam.speccy.cz/zx/asm_grafika.7z
User avatar
Einar Saukas
Bugaboo
Posts: 3145
Joined: Wed Nov 15, 2017 2:48 pm

Re: translated document of optimized graphics routines

Post by Einar Saukas »

There are lots of magazine issues here:

https://worldradiohistory.com/INTERNATI ... e%20Radio/
https://archive.org/search?query=Amaterske+Radio

Do you know when it started to publish any Sinclair-related content? I can add this magazine to ZXDB too, but it doesn't make sense to include all issues since 1952...
SamC
Microbot
Posts: 168
Joined: Sun Sep 29, 2019 9:07 pm

Re: translated document of optimized graphics routines

Post by SamC »

I am sure that articles about Sinclair computers have been published since early on. There were two series of the magazine (red and blue series).
There are incomplete lists and searches on the Internet, e.g.
https://petrfaltus.net/petr-faltus-amat ... data-1.php
http://jirky.webz.cz/index.php?page=cas ... 0&w=Hledat

Some of our colleagues here may have a database of all zx-related AR articles in files for Datalog or for Masterfile. I'll look for it and let you know.
User avatar
Einar Saukas
Bugaboo
Posts: 3145
Joined: Wed Nov 15, 2017 2:48 pm

Re: translated document of optimized graphics routines

Post by Einar Saukas »

Thanks!
User avatar
Bedazzle
Manic Miner
Posts: 305
Joined: Sun Mar 24, 2019 9:03 am

Re: translated document of optimized graphics routines

Post by Bedazzle »

andydansby wrote: Sat Sep 16, 2023 12:01 pm While learning about different assembler techniques, I occasionally come across various Russian articles. One in particular caught my interest at https://zxpress.ru/article.php?id=5429. The problem using Google translate is the odd wording that be a result of the process.
Cause I'm native, if you need some help, I can help to understand slang and poorly scanned words, where instead of Cyrillic letters there are Latin, and vice versa.
andydansby
Microbot
Posts: 148
Joined: Fri Nov 24, 2017 5:09 pm
Location: Syracuse, NY, USA
Contact:

Re: translated document of optimized graphics routines

Post by andydansby »

Bedazzle wrote: Sun Sep 17, 2023 12:40 pm Cause I'm native, if you need some help, I can help to understand slang and poorly scanned words, where instead of Cyrillic letters there are Latin, and vice versa.
It can be a challenge at times. I use ABBYY screenshot reader, paste the results in a word processor, correct any incorrect letters and remove dashes that separate words in half (especially in magazine articles).

I then paste those results in 2-3 translators to get a basic understanding of what is being said and correct the grammar as best as I can.

Slang and some technical references catch me off guard because translators will often screw them up badly like sometimes instead of "Register", it will choose the word "Battery". Translators are often odd at times.
User avatar
Bedazzle
Manic Miner
Posts: 305
Joined: Sun Mar 24, 2019 9:03 am

Re: translated document of optimized graphics routines

Post by Bedazzle »

andydansby wrote: Sun Sep 17, 2023 1:41 pm Slang and some technical references catch me off guard because translators will often screw them up badly like sometimes instead of "Register", it will choose the word "Battery". Translators are often odd at times.
After you create first automatic translation, send me both rus+eng text, and I can do quick checking. =)
User avatar
flatduckrecords
Manic Miner
Posts: 787
Joined: Thu May 07, 2020 11:47 am
Location: Oban, Scotland
Contact:

Re: translated document of optimized graphics routines

Post by flatduckrecords »

Thanks for sharing this!
andydansby wrote: Sun Sep 17, 2023 1:41 pm Translators are often odd at times.
I spotted a fun one on page three, “column of familiarity” instead of “character cell”. (I quite like that, though. Might start using it).

I’ve actually backed that new edition of the book on Kickstarter (I think they’re doing final proofing now before the print run so hopefully it will be along soon). I’m curious to see what’s been updated and now I’m really curious to compare it with these optimised routines.
andydansby
Microbot
Posts: 148
Joined: Fri Nov 24, 2017 5:09 pm
Location: Syracuse, NY, USA
Contact:

Re: translated document of optimized graphics routines

Post by andydansby »

flatduckrecords wrote: Mon Sep 18, 2023 12:59 am Thanks for sharing this!



I spotted a fun one on page three, “column of familiarity” instead of “character cell”. (I quite like that, though. Might start using it).

I’ve actually backed that new edition of the book on Kickstarter (I think they’re doing final proofing now before the print run so hopefully it will be along soon). I’m curious to see what’s been updated and now I’m really curious to compare it with these optimised routines.
Good catch.

I've moved the documents and asm file to
https://github.com/andydansby/zx_spectr ... l_routines. This will allow for easier editing. At some point I'll do a version with @Einar Saukas optimization suggestions. I might even do a Z88dk version for a tester.
User avatar
g0blinish
Manic Miner
Posts: 287
Joined: Sun Jun 17, 2018 2:54 pm

Re: translated document of optimized graphics routines

Post by g0blinish »

Post Reply