FAQ  •  Register  •  Login

how to use a standard character set

<<

programandala.net

Posts: 98

Joined: Fri Apr 09, 2010 12:50 am

Location: España/Hispanujo/Spain

Post Tue Apr 20, 2010 12:52 pm

how to use a standard character set

Sometimes, in order to use the Spanish characters (áéíóúüñÁÉÍÓÚÜÑ¿¡) in my Spectrum programs, I put them in the place of less used Spectrum chars (#, ', @...).

In the source code of my current project there's a lot of Spanish texts to be printed by the Spectrum. It would be uncomfortable to use those fake chars all over the source. Then I had a quite brilliant ;) idea: Let's use the same standard character set both in the source code and in the Spectrum!

First, I wrote a trivial asm sub to change the character set address. Then I added the character graphics, with the Spanish chars in the right position (in the ISO-8859-1 standard). The only needed trick is to fill the gaps of the unused chars. Happily, I already had all the character definitions is assembler DEFBs, in another project of mine.

This is the first part of the sub:

  Code:
sub fastcall changeCharacterSet()

   asm

systemCHARS   equ 23606

   jp actuallyChangeCharacterSet

characterSet equ $-256

;(space)
   defb %00000000
   defb %00000000
   defb %00000000
   defb %00000000
   defb %00000000
   defb %00000000
   defb %00000000
   defb %00000000
;!
   defb %00000000
   defb %00010000
   defb %00010000
   defb %00010000
   defb %00010000
   defb %00000000
   defb %00010000
   defb %00000000


And so on... This is the end:

  Code:
   defs (243-241-1)*8 ; unused chars
;ó = 243
   defb %00001000
   defb %00010000
   defb %00111000
   defb %01000100
   defb %01000100
   defb %01000100
   defb %00111000
   defb %00000000

   defs (250-243-1)*8 ; unused chars
;ú = 250
   defb %00001000
   defb %00010000
   defb %01000100
   defb %01000100
   defb %01000100
   defb %01000100
   defb %00111000
   defb %00000000

   defs (252-250-1)*8 ; unused chars
;ü = 252
   defb %01000100
   defb %00000000
   defb %01000100
   defb %01000100
   defb %01000100
   defb %01000100
   defb %00111000
   defb %00000000

actuallyChangeCharacterSet:

   ld hl,characterSet
   ld (systemCHARS),hl

   end asm
end sub


Easy, isn't it?

The next task is to hack the print.asm library in order to print all characters from 32 to 255. I show the removed or added lines (they are clearly marked):

First:

  Code:
; 1 LINE REMOVED:
;      LOCAL __PRINT_UDG


And then the rest:

  Code:
; 8 LINES REMOVED:
;      cp 80h   ; Is it an UDG or a ?
;      jp c, __SRCADDR

;      cp 90h
;      jp nc, __PRINT_UDG

      ; Print a 8 bit pattern (80h to 8Fh)

;      ld b, a
;      call PO_GR_1 ; This ROM routine will generate the bit pattern at MEM0
;      ld hl, MEM0
;      jp __PRGRAPH

PO_GR_1 EQU 0B38h

; 4 LINES REMOVED:
;__PRINT_UDG: ;REMOVED
;      sub 90h ; Sub ASC code
;      ld bc, (UDG)
;      jp __PRGRAPH0

__SOURCEADDR EQU (__SRCADDR + 1)   ; Address of the pointer to chars source
__SRCADDR:
      ld bc, (CHARS)

__PRGRAPH0:
; 1 LINE REMOVED:
;      add a, a   ; A = a * 2 (since a < 80h) ; Thanks to Metalbrain at http://foro.speccy.org
      ld l, a
      ld h, 0      ; HL = a * 2 (accumulator)
      add hl, hl
; 1 LINE ADDED:
      add hl, hl
      add hl, hl ; HL = a * 8
      add hl, bc ; HL = CHARS address

__PRGRAPH:


That's all. Now all characters from 32 to 255 are in the same set: no block graphics, no UDGs, no Basic tokens. Any desired graphic can be defined in any character code. Any standard 8-bit character set can be used. Now I can write the Spanish texts in the source and they show perfectly on the Spectrum's screen.

I'd like my hacked version to be an independent library, to be #included, and used with a new command (print224, printplus or whatever). But rigth now that task is beyond my current skill with ZX Basic. Any help?

Another issue is to use the gaps of the unused chars for variables, but I'm still not sure how to use asm labels in ZX Basic. I have to explore it. Any help?

Now I will tinker with the second part of the system: I have to modify my own input routine, to let it accept some key combinations (e.g. Symbol Shift (+Shift)+letter) to get the Spanish characters...
<<

boriel

Site Admin

Posts: 1548

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Apr 20, 2010 6:15 pm

Re: how to use a standard character set

Having "page codes" is a nice idea. I implemented UDG just for compatibility, but there is a simple way to specify a different PRINT routine, by using #ifdef directives, and invoking them at the command line. It could be something like this:

zxb.py --DUSE_PRINT_SPANISH ...

  Code:
# FILE: print.asm

#IFDEF USE_PRINT_SPANISH
#include <print_spanish_codes.asm>
#ELSE
#include <print_standard.asm>
#END

This could be done for many page codes. On the other side, you could easily make your own strcode conversion which changes spanish chars to UDG, for example. In fact, this is how most of the print routines work, as far as I know, or changing the default charset address with POKE.
<<

programandala.net

Posts: 98

Joined: Fri Apr 09, 2010 12:50 am

Location: España/Hispanujo/Spain

Post Tue Apr 20, 2010 6:59 pm

Re: how to use a standard character set

boriel wrote:zxb.py --DUSE_PRINT_SPANISH


error: no such option -D
error: no such option --D


Is it a planned option for a future release?
<<

boriel

Site Admin

Posts: 1548

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Apr 20, 2010 7:10 pm

Re: how to use a standard character set

programandala.net wrote:
boriel wrote:zxb.py --DUSE_PRINT_SPANISH


error: no such option -D
error: no such option --D


Is it a planned option for a future release?

It was just an idea! :P In fact, you could already implement it by modifing print.asm with your changes, as suggested above.

Note: use -D option or --define (see -h for help). Single dash is for short options, whilst double-dash (--) is for long ones. Try your command again.

Return to How-To & Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO