UDG in VDC and VIC-II for the C128 target

Requests for features
Fabrizio
Member
Posts: 115
Joined: Tue Jul 11, 2017 9:28 pm

UDG in VDC and VIC-II for the C128 target

Post by Fabrizio »

The C128 target is a relatively popular target that lacks UDG support in Z88DK.

It does have software sprites support in VDC mode, though. They are cool but extremely slow due to the hardware. So they are not really meant for animations.

Support for UDG in VDC (80 column) mode would allow developers to code games and programs for VDC with much faster graphics.
The VDC has up to 512 tile shapes. So it is a pitty, they are not exploited by Z88DK.
Moreover VDC text mode can have colors for tiles even with the most common 16K video ram configuration.
So a standard C128 could have some graphics with a freely chosen color.

Support for UDG in VIC-II mode would also make Z88DK an alternative tool for developing games for the C128.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by dom »

As I mentioned I'd like to do have done this, and I'm still interested in doing it, however my todo list seems to be getting far too long for me to commit at the moment.

However, you mentioned you had sample code - even 6502 code would be helpful and save a bit of documentation reading!
Fabrizio
Member
Posts: 115
Joined: Tue Jul 11, 2017 9:28 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by Fabrizio »

I do have trivial sample code for UDG in VIC-II mode, which is almost but not fully the same as its C64 equivalent.
For the VDC (most intresting mode IMHO) I must see what I have... The VDC is ugly to program as it requires to do many indirections and to check if the memory is ready to be accessed. If you do not do this, it randomly fails.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by stefano »

exactly. moreover the choice of the memory banks for z88dk is close to the cp/m one but not identical, I suppose enabling a different font in RAM is not the easiest thing to do.
I just experimented a bit using a BASIC example as a reference, but the BASIC runs on different banks and the interpreter is not badly affected by the bank switching.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by stefano »

stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by stefano »

@Fabrizio, I think I've been able to extract from the online books what you need to redefine the C128 fonts:

x=inp(0xD018); // get the VIC address register
x=x&0xF0; // keep the text page offset only
outp(0xD018,0x0C+x); // update character generator ptr to 12288
memcpy(12288,font, 512);

// Possibly valid font positions with z88dk:
// $0A = 10248 (risky.. zorg relocation needed in any case)
// $0C = 12288
// $0E = 14336

shortcut for the inp/outp above (probably you don't need to switch between text pages):
outp(0xD018,0x8C); //..or 0x8e to put the font at $14336.
The font can be probably loaded as a byte block, but I havent tried it (the BANK settings can be misleading).

..to build your programs you need to shift your code a bit: add "-zorg=16384" ..to be safe, you still have plenty of space

@Dominic, ...passing the T64 file to the X128 emulator saves a lot of time, I suggest you to try.

X128 A.T64 (flash-loads the binary block)
LOAD/RUN (optional, or just BANK0:SYS.. to be faster)
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by stefano »

..now that I found the trick, a C128 specific version of dstar.c was ready in a flash :)
So a C128 user can choose between a small, fast version on the 40 columns monitor or an high resolution variant, but more accurate and a little slower.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by dom »

Can you post some screenshots? :)
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by stefano »

Sure. In 40 columns text mode we could get only this picture, before:
dstar128-lorez.png
..this is the result using the font redefinition feature:
dstar128-vic.png
An intermediate resolution, based on the "text6"/UDG library should be fairly simple to get.

In High Resolution (thus special monitor), this is the currently best sprite size choice for the C128:
dstar-c128hr.png
You do not have the required permissions to view the files attached to this post.
Fabrizio
Member
Posts: 115
Joined: Tue Jul 11, 2017 9:28 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by Fabrizio »

It is not clear to me how I am supposed to use it.
Can I use the same code I use for all other targets with UDG graphics?
Can I re-use the same font/udg Assembly files I link when compiling?
Fabrizio
Member
Posts: 115
Joined: Tue Jul 11, 2017 9:28 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by Fabrizio »

Where should I put the out command?

void *param = &udgs;
console_ioctl(IOCTL_GENCON_SET_FONT32, &param);

...
{
...
int mode = SCREEN_MODE;
console_ioctl(IOCTL_GENCON_SET_MODE, &mode);

}
Fabrizio
Member
Posts: 115
Joined: Tue Jul 11, 2017 9:28 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by Fabrizio »

If I try to compile it as I do with other UDG targets I get errors:
"
c128_z80_40col: $(ASSETS_PATH)/z88dk_xchase.asm
$(Z88DK_PATH)$(MYZ88DK) +c128 $(SCCZ80_OPTS) -zorg=16384 \
-pragma-redirect:fputc_cons=fputc_cons_generic \
$(INCLUDE_OPTS) \
-lndos -subtype=disk \
-D__C128_Z80__ -DFORCE_XSIZE=40 \
-DSOUNDS \
-DFORCE_BIT_BANG \
-DFORCE_CONIO_LIB \
-DCONIO -DUDG_GRAPHICS \
$(FULL_FILES) \
$(ASSETS_PATH)/z88dk_xchase.asm \
$(CROSS_LIB_PATH)/display/init_graphics/z88dk/udg/udg_init_graphics.c \
-create-app -oa40.bin
"
I get:
"
Error at file 'fputc_cons_generic_ioctl.c::console_ioctl' line 6: symbol 'generi
c_console_ioctl' not defined
Error at file 'fputc_cons_generic.inc' line 114: symbol 'generic_console_scrollu
p' not defined
Error at file 'fputc_cons_generic.inc' line 131: symbol 'generic_console_printc'
not defined
Error at file 'fputc_cons_generic.inc' line 332: symbol 'generic_console_set_ink
' not defined
Error at file 'fputc_cons_generic.inc' line 337: symbol 'generic_console_set_pap
er' not defined
Error at file 'fputc_cons_generic.inc' line 342: symbol 'generic_console_cls' no
t defined
Error at file 'fputc_cons_generic.inc' line 369: symbol 'generic_console_set_att
ribute' not defined
Error at file 'fputc_cons_generic.inc' line 419: symbol 'generic_console_scrollu
p' not defined
Error at file 'fputc_cons_generic.inc' line 443: symbol 'generic_console_set_att
ribute' not defined
Error at file 'conio/ioctl_vars.asm' line 8: symbol 'CLIB_GENCON_CAPS' not defin
ed
Errors in source file c:/z88dk/\lib\target\c128\classic\c128_crt0.asm:
Error at file 'fputc_cons_generic_ioctl.c::console_ioctl' line 6: symbol 'generi
c_console_ioctl' not defined
Error at file 'fputc_cons_generic.inc' line 114: symbol 'generic_console_scrollu
p' not defined
Error at file 'fputc_cons_generic.inc' line 131: symbol 'generic_console_printc'
not defined
Error at file 'fputc_cons_generic.inc' line 332: symbol 'generic_console_set_ink
' not defined
Error at file 'fputc_cons_generic.inc' line 337: symbol 'generic_console_set_pap
er' not defined
Error at file 'fputc_cons_generic.inc' line 342: symbol 'generic_console_cls' no
t defined
Error at file 'fputc_cons_generic.inc' line 369: symbol 'generic_console_set_att
ribute' not defined
Error at file 'fputc_cons_generic.inc' line 419: symbol 'generic_console_scrollu
p' not defined
Error at file 'fputc_cons_generic.inc' line 443: symbol 'generic_console_set_att
ribute' not defined
Error at file 'conio/ioctl_vars.asm' line 8: symbol 'CLIB_GENCON_CAPS' not defin
ed
make: *** [Makefile.tiles:629: c128_z80_40col] Error 1
"
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by Timmy »

Can I just say I like these new screenshots? :)
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by dom »

Stefano has done it in a target specific way - when I get time I'll tidy it up and gencon it for ease of use.

dstar for the c128 is here: https://github.com/z88dk/z88dk/blob/mas ... 28/dstar.c - the relevant code is here: https://github.com/z88dk/z88dk/blob/mas ... star.c#L97 I think.
Fabrizio
Member
Posts: 115
Joined: Tue Jul 11, 2017 9:28 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by Fabrizio »

@dom I don't understand where the graphics comes from as the dstar.c comment does not mention any file to link.
Fabrizio
Member
Posts: 115
Joined: Tue Jul 11, 2017 9:28 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by Fabrizio »

I am very thankful with Stefano's solution to get graphics on the C128 VIC-II (40 columns) but it does not provide a solution for the feature request of this thread.

The problem is that VDC sprites are not just a little slower (it is not a complain on you guys but it is the slow hardware).
They are about 100-1000 or more slower than VIC-II characters.
You can literally see each single 8x8 sprite being redrawn while on the VIC-II you can redraw hundreds of characters at the same time in a tiny fraction of a second. Even updating the score once in a while, slows the game down.
DSTAR is not an action game.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by stefano »

@Fabrizio, I'm sorry it is not solving.
Surely it is not straightforward (yet). Still, I'm happy I'm beginning to understand how the C128 beast works, it is not rocket science but quite complex already :)
@Timmy, I just finished a new "UDG" mid resolution mode (80x75), I'm adding it soon (possibly moving some more code in a general text6 section).
dstar128-udg.png
You do not have the required permissions to view the files attached to this post.
Fabrizio
Member
Posts: 115
Joined: Tue Jul 11, 2017 9:28 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by Fabrizio »

This is how I modify characters in BASIC for the VDC:

Code: Select all

0 fast:graphic5,1:rem c128 charset rom copy
10 bank14:fora=53248to57343:pokea-40960,peek(a):next: rem copy from rom
20 bank15:poke2604,peek(2604)and240or12: rem set chars at 12288 by vic-iie shadow register
30 rem c128 charset copy from 12288 to vdc
35 poke12288,255:poke12289,255:rem modify @ character
40 sysdec("cdda"),,28:rrega:cs=aand224:rem get charset data address
50 sysdec("cdcc"),cs,18:sysdec("cdcc"),0,19:rem set position to vdc charset data
60 forx=0to255:forf=0to7:sysdec("cdcc"),peek(12288+(x*8)+f),31:rem write data
70 nextf:forz=0to7:sysdec("cdcc"),0,31:nextz,x:rem fill zero next 8 bytes
Last edited by dom on Tue Jan 12, 2021 5:21 pm, edited 1 time in total.
Reason: cleanup formatting
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by dom »

stefano wrote: Mon Jan 11, 2021 12:33 pm@Dominic, ...passing the T64 file to the X128 emulator saves a lot of time, I suggest you to try.

X128 A.T64 (flash-loads the binary block)
LOAD/RUN (optional, or just BANK0:SYS.. to be faster)
Thank you, I've now got something running (I went through the vice 3.x cul-de-sac of course), now to find some docs on the attributes...

Don't we need to reorg the binary though? It looks like the UDGs overlay the start of the code at the moment?
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by stefano »

I tried to lower the font position, but something is still overflowing, e.g. the code still needs to shifted at 16384 or more.
Sometimes is runs fine but the screen area and the font are somewhat impacted.. given my current ignorance I'd simply move the ORG location at 16384.
Hopefully the extra free space can be used for the vdc.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by stefano »

<grin> I forgot the vice version trap!
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by dom »

Yes, that's my plan as well, just org to $5000 and have done with it. That gives us 256 characters to play with.

Almost there BTW (not bad for an hour or so thanks to your research and experiments):
Screenshot 2021-01-12 at 20.57.18.png
Still need to figure out attributes, but I do love making everything look like a Spectrum.
You do not have the required permissions to view the files attached to this post.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by dom »

Okay, @fabrizio I've pushed some changes that hopefully do what you want.

If you compile for the c128 with -clib=gencon then generic console is active by default which then allows you to use console_ioctl(IOCTL_GENCON_SET_FONT32, &param); and console_ioctl(IOCTL_GENCON_SET_UDG, &param);

cvpeek() is also working so it becomes more like every other platform. Hopefully this will work for you.
Fabrizio
Member
Posts: 115
Joined: Tue Jul 11, 2017 9:28 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by Fabrizio »

Thanks guys! I have managed to compile Cross Snake with graphics in 40 column mode. It works fine.

The only problems left are old problems with the C128:
1. some bit bang sounds are totally wrong (e.g., bit_fx(7) and bit_fx(1), which also last much longer than expected. bit_fx(7) is not a noise sound, so it may not be related to wrong rom address used as "random" source).
I have opened issue #1669 with the code that reproduces the problem and a sample of the wrong sound.

2. c128 starts slowly with a sort of an initial "pause" (I suppose it is copying stuff in memory. Is the copy done by the MOS8502 or Zilog 80?):
I have suggested to Stefano setting MOS8502 2mhz mode and disabling the VIC-IIe ONLY during this phase but this could break the game.
Even in Z80 mode, it seems that 2mhz can help a little bit:

Code: Select all

__asm
; Disable VIC-IIe chip
	ld a,0
	ld bc,$d011
	out (c),a
    
; Set fast mode
	ld a,1
	ld bc,$d030
	out (c),a
__endasm;
IMPORTANT:
Be aware that I once had these two settings set after the initial pause and someone reported this setting broke the game on the real hardware.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: UDG in VDC and VIC-II for the C128 target

Post by stefano »

I'm aware of the problem #1. The SID is obviously different than the other sound devices we are used to control.
I vaguely remember I suspected it was consequence of a limit on the emulator, not expecting the SID volume to be controlled as a square wave device.
Is it possible to have this bug checked also on the real hardware?
Post Reply