Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ULAplus support
#1
since i'm seeing so many good games from MojonTwins supporting ULAplus, and its implementation looked so simple, i tried to code some library and example for that - be welcome testing it (i think would be a good idea if this could be implemented defaultly on zxbasic-compiler, what do you all think?)
(for now i'm testing this on SpectEmu on Wine, while there are no native emulators for LInux)

library/ulaplus.bas
Code:
dim tmpv as uinteger
dim fdbkv as ubyte

function ulapluscheck():
  tmpv=in(65339):pause 1:fdbkv=0
  out 48955,0:out 65339,0:pause 1
  if in(65339)<>tmpv then:fdbkv=1:out 48955,0:out 65339,tmpv:pause 1:end if
  return fdbkv
  end function

sub ulapluspalette(clv as ubyte, vlv as ubyte):
  out 48955,(clv band 63):out 65339,vlv:pause 1
  end sub

sub ulaplusswitch(flgv as ubyte):
  out 48955,64:out 65339,(flgv band 1):pause 1
  end sub

ulaplus_example.bas
Code:
#include "library/ulaplus.bas"

ulaplusswitch(1):cls

a$="ULAplus is not present"
if ulapluscheck()<>0 then:a$="ULAplus is present":end if
print at 0,0;a$

for fl=0 to 1
  flash fl
  for hb=0 to 1
    bright hb
    for pa=0 to 7
      paper pa:inverse 0
      print " ";
      next
    for ik=0 to 7
      ink ik:inverse 1
      print " ";
      next
    next:next

for i=0 to 63
  ulapluspalette(i, int(rnd*255) )
  next

pause 0
Reply
#2
oops, i forgot to add a 'ulaplusgetpalette()' function - this is really important to get the palette values back - the example below illustrates the usage of it

library/ulaplus.bas
Code:
dim tmpv as uinteger
dim fdbkv as ubyte

function ulapluscheck():
  tmpv=in(65339):pause 1:fdbkv=0
  out 48955,0:out 65339,0:pause 1
  if in(65339)<>tmpv then:fdbkv=1:out 48955,0:out 65339,tmpv:pause 1:end if
  return fdbkv
  end function

sub ulapluspalette(clv as ubyte, vlv as ubyte):
  out 48955,(clv band 63):out 65339,vlv:pause 1
  end sub

function ulaplusgetpalette(clv as ubyte)
  out 48955,(clv band 63)
  return in(65339)
  pause 1
  end function

sub ulaplusswitch(flgv as ubyte):
  out 48955,64:out 65339,(flgv band 1):pause 1
  end sub

ulaplus_example.bas
Code:
#include "library/ulaplus.bas"
ulaplusswitch(1):cls
a$="ULAplus is not present"
if ulapluscheck()<>0 then:a$="ULAplus is present":end if
print at 0,0;a$
for fl=0 to 1:flash fl
  for hb=0 to 1:bright hb
    for ik=0 to 7
      ink ik:inverse 1:print " ";
      next
    for pa=0 to 7
      paper pa:inverse 0:print " ";
      next
    next:next
for i=0 to 63
  'ulapluspalette(i,int(rnd*255))
  ulapluspalette(i,i)
  next
print
ink 0:paper 7:bright 1
for i=0 to 63
  print ulaplusgetpalette(i);",";
  next i
pause 0
Reply
#3
Another update

The first one is related to a more simple use of 'ink' and 'paper' - since it's a bit hard to locate a colour between 0 and 63 using 'ink:paper:bright:flash:inverse', i added a sub that gives priority to 'ink' (between 0 and 63), and uses the less significative 3 bits from paper, due on ULAplus limitation (which is limited to use the same 16 colour group from ink, and not the same 8 colour group) - i think the code example explains a bit how it works.

The other function i added is related to use more easily hexcolours on ULAplus - for example, besides the hexcolour format used on webpages, for red colour, is '#FF0000', it would be 12bit instead of 24bit, like '#F00', which on the code will be used as '0F00h'

on the example, i used the colour 15 for the border because it were the 'border 7' (and 'paper 7:flash 0: bright 0'), colour 0 for the default ink (ink 0:flash 0:bright 0), and all other between colour 48 and colour 63, for illustrating how is it used on the last of all 4 16c cluts (equivalent of 'flash 1: bright 1')

library/ulaplus.bas
Code:
'- ULAplus library for Boriel's zxbasic-compiler
'- 20111205164150 - (ↄ) Paulo Silva - http://nitrofurano.altervista.org
'- This file is released under the GPL v3 License

dim tmpv as uinteger
dim fdbkv as ubyte

function ulapluscheck():
  tmpv=in(65339):pause 1:fdbkv=0
  out 48955,0:out 65339,0:pause 1
  if in(65339)<>tmpv then:fdbkv=1:out 48955,0:out 65339,tmpv:pause 1:end if
  return fdbkv
  end function

sub ulapluspalette(clv as ubyte, vlv as ubyte):
  out 48955,(clv band 63):out 65339,vlv:pause 1
  end sub

function ulaplusgetpalette(clv as ubyte)
  out 48955,(clv band 63)
  return in(65339)
  pause 1
  end function

sub ulaplusswitch(flgv as ubyte):
  out 48955,64:out 65339,(flgv band 1):pause 1
  end sub

sub ulaplusattr(ikv as ubyte,pav as ubyte):
  '- usage: ink priority (from 0 to 63), and only using 3 bits lsb from paper
  inverse 0:ink(ikv band 7):paper(pav band 7)
  bright((ikv band 16)/16):flash((ikv band 32)/32)
  if (ikv band 8)<>0 then:
    inverse 1:ink(pav band 7):paper(ikv band 7)
    end if
  end sub

function ulaplushexcolour(hxcv as uinteger):
  tmpv=(hxcv band 12)/4
  tmpv=tmpv bor(hxcv band 224)
  hxcv=int(hxcv/256)
  tmpv=tmpv bor((hxcv band 14)*2)
  return tmpv
  end function

example01.bas
Code:
#include "library/ulaplus.bas"
ulaplusswitch(1):cls
bold 1

ulaplusattr(0,15)
cls
ulapluspalette(0,ulaplushexcolour(0398h))
ulapluspalette(15,ulaplushexcolour(0275h))
ulapluspalette(57,ulaplushexcolour(0874h))
ulapluspalette(49,ulaplushexcolour(0543h))
ulapluspalette(58,ulaplushexcolour(0783h))

print at 0,0;"";
print "test - using palette from http://www.colourlovers.com/palette/1779157/Reflect_Hope_F?widths=0":print
print "hexcolours (12bit):"
print "#275,#874,#398,#543,#783":print

ulaplusattr(49,57):print "hello world!"
ulaplusattr(57,49):print "hello world!":print

ulaplusattr(49,58):print "hello world!"
ulaplusattr(58,49):print "hello world!":print

ulaplusattr(15,15):print "\::";
ulaplusattr(57,57):print "\::";
ulaplusattr(0,0):print "\::";
ulaplusattr(49,49):print "\::";
ulaplusattr(58,58):print "\::";

pause 0

screenshot:
[Image: 201112051653251280x800s.th.png]
Reply
#4
nice colours
Reply
#5
You should add these to the library

<!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m -->


Is it actually necessary to have tmpv and fdbkv as global variables?
Reply
#6
thanks, but all credits about the colour palette goes to the palette author, at his colourlovers account! Smile (even if ULAplus adjusts it to 8bit)
btw, i'm looking for better names for library variables, since i'm a bit messy on that - which kind of norm here must we follow?
Reply
#7
Quote: #include <ulaplus.bas>
ulaplusswitch(1):cls
bold 1

ulaplusattr(0,15)
cls
ulapluspalette(0,ulaplushexcolour(0398h))
ulapluspalette(15,ulaplushexcolour(0275h))
ulapluspalette(57,ulaplushexcolour(0874h))
ulapluspalette(49,ulaplushexcolour(0543h))
ulapluspalette(58,ulaplushexcolour(0783h))

print at 0,0;"";
print "test - using palette from <!-- m --><a class="postlink" href="http://www.colourlovers.com/palette/1779157/Reflect_Hope_F?widths=0">http://www.colourlovers.com/palette/177 ... F?widths=0</a><!-- m -->":print
print "hexcolours (12bit):"
print "#275,#874,#398,#543,#783":print

ulaplusattr(49,57):print "hello world!"
ulaplusattr(57,49):print "hello world!":print

ulaplusattr(49,58):print "hello world!"
ulaplusattr(58,49):print "hello world!":print

ulaplusattr(15,15):print "\::";
ulaplusattr(57,57):print "\::";
ulaplusattr(0,0):print "\::";
ulaplusattr(49,49):print "\::";
ulaplusattr(58,58):print "\::";

pause 0

Quote: 11:08:32 -> Compilation starts(31 Lines)
 11:08:32 -> Source new.bor saved
 11:08:32 -> C:\Program Files\Boriel Tm\ZX Basic Compiler\zxb.exe "temp.bor" -S 24576 -o "C:\Program Files\Boriel Tm\ZX Basic Compiler\new.bin"

 11:08:33 -> Exit code: 1

temp.bor:30: Error: illegal preprocessor character '
I'm always on the chat or facebook.
Reply
#8
That seems to happen with included files for some reason. Just add an empty line at the top of ulaplus.bas to get it working.
Reply
#9
na_th_an Wrote:That seems to happen with included files for some reason. Just add an empty line at the top of ulaplus.bas to get it working.
That's a bug in the ZXB Preprocessor, supposedly fixed in the latest version. Which version are you using?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)