FAQ  •  Register  •  Login

ULAplus support

<<

nitrofurano

Posts: 186

Joined: Thu Sep 29, 2011 12:44 pm

Location: Porto, Portugal

Post Mon Nov 07, 2011 11:59 am

ULAplus support

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

nitrofurano

Posts: 186

Joined: Thu Sep 29, 2011 12:44 pm

Location: Porto, Portugal

Post Mon Nov 07, 2011 8:26 pm

Re: ULAplus support

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

nitrofurano

Posts: 186

Joined: Thu Sep 29, 2011 12:44 pm

Location: Porto, Portugal

Post Mon Dec 05, 2011 5:07 pm

Re: ULAplus support

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

slenkar

Posts: 271

Joined: Sun Feb 13, 2011 3:33 am

Location: Kentucky US, used to be Birmingham UK

Post Mon Dec 05, 2011 9:00 pm

Re: ULAplus support

nice colours
<<

britlion

Posts: 722

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Thu Dec 08, 2011 3:48 pm

Re: ULAplus support

You should add these to the library

http://www.boriel.com/wiki/en/index.php ... IC:Library


Is it actually necessary to have tmpv and fdbkv as global variables?
<<

nitrofurano

Posts: 186

Joined: Thu Sep 29, 2011 12:44 pm

Location: Porto, Portugal

Post Mon Dec 12, 2011 1:26 pm

Re: ULAplus support

thanks, but all credits about the colour palette goes to the palette author, at his colourlovers account! :) (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?
<<

ardentcrest

Posts: 49

Joined: Fri Oct 11, 2013 5:19 pm

Post Fri Oct 18, 2013 10:09 am

Re: ULAplus support

#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 http://www.colourlovers.com/palette/177 ... 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


 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 '
He's a Bot Jim, But not as we know It
<<

na_th_an

Posts: 73

Joined: Fri May 07, 2010 7:34 am

Post Tue Oct 22, 2013 11:54 am

Re: ULAplus support

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

boriel

Site Admin

Posts: 1277

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Oct 22, 2013 9:24 pm

Re: ULAplus support

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?

Return to Library

Who is online

Users browsing this forum: No registered users and 1 guest

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

phpBB SEO