Browse Source

h68units: added an initial version of an IOCS API unit with some graphics related calls, and an example program using it

Karoly Balogh 1 year ago
parent
commit
e571bd8693

+ 71 - 0
packages/h68units/examples/gradient.pas

@@ -0,0 +1,71 @@
+{
+    Copyright (c) 2024 Karoly Balogh
+
+    32K color gradients on a 256x256 screen
+    Example program for Free Pascal's Human 68k bindings
+
+    This example program is in the Public Domain under the terms of
+    Unlicense: http://unlicense.org/
+
+ **********************************************************************}
+
+program gradient;
+
+uses
+  h68kdos, h68kiocs;
+
+const
+  GVRAM_START = $C00000;
+  COMPONENT_MASK = %11111000;
+
+var
+  super: longint;
+  lastmode: longint;
+
+procedure gfx_init;
+begin
+  lastmode:=_iocs_crtmod(-1);
+  _iocs_crtmod(14);  { 256x256, 64k, 31Khz }
+  _iocs_vpage(0);
+  _iocs_g_clr_on;
+  _iocs_b_curoff;
+end;
+
+procedure gfx_done;
+begin
+  writeln('Press Enter...');
+  readln;
+  _iocs_crtmod(lastmode);
+  _iocs_b_curon;
+end;
+
+procedure gfx_gradient;
+var
+  addr: pword;
+  x,y: longint;
+  r,b: longint;
+begin
+  addr:=pword(GVRAM_START);
+  super:=h68kdos_super(0);
+
+  for y:=0 to 255 do
+    begin
+      r:=(y and COMPONENT_MASK) shl 3;
+      b:=((255-y) and COMPONENT_MASK) shr 2;
+      for x:=0 to 255 do
+        begin
+          addr^:=((x and COMPONENT_MASK) shl 8) or
+                 r or b or 1;
+          inc(addr);
+        end;
+      inc(addr,256);
+    end;
+
+  h68kdos_super(super);
+end;
+
+begin
+  gfx_init;
+  gfx_gradient;
+  gfx_done;
+end.

+ 4 - 0
packages/h68units/fpmake.pp

@@ -34,6 +34,10 @@ begin
       begin
         AddInclude('h68kdos.inc');
       end;
+    T:=P.Targets.AddUnit('h68kiocs.pas');
+
+    P.ExamplePath.Add('examples');
+    T:=P.Targets.AddExampleProgram('gradient.pas');
 
     P.Sources.AddDoc('README.md');
 

+ 3 - 0
packages/h68units/namespaced/Human68kApi.IOCS.pas

@@ -0,0 +1,3 @@
+unit Human68kApi.IOCS;
+{$DEFINE FPC_DOTTEDUNITS}
+{$i h68kiocs.pas}

+ 63 - 0
packages/h68units/src/h68kiocs.pas

@@ -0,0 +1,63 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 20243 by Free Pascal development team
+
+    IOCS API unit for Human 68k (Sharp X68000)
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{$IFNDEF FPC_DOTTEDUNITS}
+unit h68kiocs;
+{$ENDIF FPC_DOTTEDUNITS}
+
+interface
+
+procedure _iocs_b_curon;
+procedure _iocs_b_curoff;
+function _iocs_crtmod(mode: longint): longint;
+procedure _iocs_g_clr_on;
+function _iocs_vpage(page: longint): longint;
+
+
+implementation
+
+procedure _iocs_b_curon; assembler; nostackframe;
+asm
+  moveq.l #$1e,d0
+  trap #15
+end;
+
+procedure _iocs_b_curoff; assembler; nostackframe;
+asm
+  moveq.l #$1f,d0
+  trap #15
+end;
+
+function _iocs_crtmod(mode: longint): longint; assembler; nostackframe;
+asm
+  move.l d0,d1
+  moveq.l #$10,d0
+  trap #15
+end;
+
+procedure _iocs_g_clr_on; assembler; nostackframe;
+asm
+  moveq.l #$ffffff90,d0
+  trap #15
+end;
+
+function _iocs_vpage(page: longint): longint; assembler; nostackframe;
+asm
+  move.l d0,d1
+  moveq.l #$ffffffb2,d0
+  trap #15
+end;
+
+end.