Skip to content

Commit

Permalink
Add mouse library
Browse files Browse the repository at this point in the history
  • Loading branch information
drmortalwombat committed Jan 22, 2023
1 parent 0fae7ab commit 946b1fe
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 12 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ The compiler is command line driven, and creates an executable .prg file.
* -O2: more aggressive speed optimizations including auto inline of small functions
* -O3: aggressive optimization for speed
* -Os: optimize for size
* -Oi: enable auto inline of small functions (part of O2/O3)
* -Oa: optimize inline assembler (part of O2/O3)
* -tf: target format, may be prg, crt or bin
* -d64 : create a d64 disk image
* -f : add a binary file to the disk image
Expand Down Expand Up @@ -688,6 +690,11 @@ Similar to its hires counterpart but using different colors and patterns.

Draws filled random circles and fills the space using flood fill.

#### Painting with mouse or joystick "paint.c"

Paint on the screen with mouse or joystick. Keyboard 0..9 for color selection, HOME to clear the screen.


#### 3D Function plotter "func3d.c"

Similar to its hires counterpart but using four shades of grey.
Expand Down
4 changes: 4 additions & 0 deletions include/c64/cia.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "cia.h"

byte ciaa_pra_def;

void cia_init(void)
{
cia1.icr = 0x7f;
Expand All @@ -19,4 +21,6 @@ void cia_init(void)

char i0 = cia1.icr;
char i1 = cia2.icr;

ciaa_pra_def = 0x7f;
}
2 changes: 2 additions & 0 deletions include/c64/cia.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct CIA
#define cia1 (*((struct CIA *)0xdc00))
#define cia2 (*((struct CIA *)0xdd00))

extern byte ciaa_pra_def;

void cia_init(void);

#pragma compile("cia.c")
Expand Down
2 changes: 1 addition & 1 deletion include/c64/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ void keyb_poll(void)
}
}

cia1.pra = 0xff;
cia1.pra = ciaa_pra_def;
}
52 changes: 52 additions & 0 deletions include/c64/mouse.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "mouse.h"
#include "sid.h"
#include "cia.h"

sbyte mouse_dx, mouse_dy;
bool mouse_lb, mouse_rb;
static char mouse_px, mouse_py;
static char mouse_port;

inline signed char dpos(char * old, char new)
{
new = (new & 0x7f) >> 1;

char diff = (new - *old) & 0x3f;

if (diff >= 0x20)
{
*old = new;
return diff | 0xe0;
}
else if (diff)
{
*old = new;
return diff;
}

return 0;
}

void mouse_poll(void)
{
char b = ((volatile char *)0xdc00)[mouse_port];
mouse_rb = (b & 0x01) == 0;
mouse_lb = (b & 0x10) == 0;

char x = sid.potx, y = sid.poty;

mouse_dx = dpos(&mouse_px, x);
mouse_dy = dpos(&mouse_py, y);
}

void mouse_arm(char n)
{
mouse_port = n;
cia1.pra = ciaa_pra_def = n ? 0x7f : 0xbf;
}

void mouse_init(void)
{
mouse_arm(1);
mouse_poll();
}
26 changes: 26 additions & 0 deletions include/c64/mouse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef C64_MOUSE_H
#define C64_MOUSE_H

#include "types.h"

extern sbyte mouse_dx, mouse_dy;
extern bool mouse_lb, mouse_rb;


void mouse_init(void);

// arm the potentiometer input for the selected mouse input
// needs ~4ms to stabilize

void mouse_arm(char n);

// poll mouse input for selected mouse, but the relative
// movement into mouse_dx/dy and the button state into
// mouse_lb/mouse_rb

void mouse_poll(void);

#pragma compile("mouse.c")

#endif

5 changes: 3 additions & 2 deletions oscar64/CompilerTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

static const uint64 COPT_OPTIMIZE_BASIC = 0x00000001;
static const uint64 COPT_OPTIMIZE_INLINE = 0x00000002;
static const uint64 COPT_OPTIMIZE_ASSEMBLER = 0x00000004;

static const uint64 COPT_OPTIMIZE_AUTO_INLINE = 0x00000010;
static const uint64 COPT_OPTIMIZE_AUTO_INLINE_ALL = 0x00000020;
Expand Down Expand Up @@ -32,9 +33,9 @@ static const uint64 COPT_OPTIMIZE_DEFAULT = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_

static const uint64 COPT_OPTIMIZE_SIZE = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_CONST_EXPRESSIONS | COPT_OPTIMIZE_CODE_SIZE;

static const uint64 COPT_OPTIMIZE_SPEED = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_AUTO_INLINE | COPT_OPTIMIZE_AUTO_UNROLL | COPT_OPTIMIZE_CONST_EXPRESSIONS;
static const uint64 COPT_OPTIMIZE_SPEED = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_AUTO_INLINE | COPT_OPTIMIZE_AUTO_UNROLL | COPT_OPTIMIZE_CONST_EXPRESSIONS | COPT_OPTIMIZE_ASSEMBLER;

static const uint64 COPT_OPTIMIZE_ALL = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_AUTO_INLINE | COPT_OPTIMIZE_AUTO_INLINE_ALL | COPT_OPTIMIZE_AUTO_UNROLL | COPT_OPTIMIZE_CONST_EXPRESSIONS;
static const uint64 COPT_OPTIMIZE_ALL = COPT_OPTIMIZE_BASIC | COPT_OPTIMIZE_INLINE | COPT_OPTIMIZE_AUTO_INLINE | COPT_OPTIMIZE_AUTO_INLINE_ALL | COPT_OPTIMIZE_AUTO_UNROLL | COPT_OPTIMIZE_CONST_EXPRESSIONS | COPT_OPTIMIZE_ASSEMBLER;

struct CompilerSettings
{
Expand Down
2 changes: 1 addition & 1 deletion oscar64/NativeCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11533,7 +11533,7 @@ void NativeCodeBasicBlock::CallAssembler(InterCodeProcedure* proc, NativeCodePro

assert(ins->mSrc[0].mLinkerObject);

if (ins->mCode == IC_ASSEMBLER)
if (ins->mCode == IC_ASSEMBLER && (proc->mModule->mCompilerOptions & COPT_OPTIMIZE_ASSEMBLER))
{
GrowingArray<NativeCodeInstruction> tains(NativeCodeInstruction(ASMIT_INV, ASMIM_IMPLIED));

Expand Down
6 changes: 5 additions & 1 deletion oscar64/oscar64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main2(int argc, const char** argv)

#else
strcpy(strProductName, "oscar64");
strcpy(strProductVersion, "1.14.181");
strcpy(strProductVersion, "1.15.182");

#ifdef __APPLE__
uint32_t length = sizeof(basePath);
Expand Down Expand Up @@ -178,6 +178,10 @@ int main2(int argc, const char** argv)
compiler->mCompilerOptions |= COPT_OPTIMIZE_ALL;
else if (arg[2] == 's')
compiler->mCompilerOptions |= COPT_OPTIMIZE_SIZE;
else if (arg[2] == 'a')
compiler->mCompilerOptions |= COPT_OPTIMIZE_ASSEMBLER;
else if (arg[2] == 'i')
compiler->mCompilerOptions |= COPT_OPTIMIZE_AUTO_INLINE;
}
else if (arg[1] == 'e')
{
Expand Down
8 changes: 4 additions & 4 deletions oscar64/oscar64.rc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,14,181,0
PRODUCTVERSION 1,14,181,0
FILEVERSION 1,15,182,0
PRODUCTVERSION 1,15,182,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -43,12 +43,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "oscar64"
VALUE "FileDescription", "oscar64 compiler"
VALUE "FileVersion", "1.14.181.0"
VALUE "FileVersion", "1.15.182.0"
VALUE "InternalName", "oscar64.exe"
VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "oscar64.exe"
VALUE "ProductName", "oscar64"
VALUE "ProductVersion", "1.14.181.0"
VALUE "ProductVersion", "1.15.182.0"
END
END
BLOCK "VarFileInfo"
Expand Down
110 changes: 107 additions & 3 deletions oscar64setup/oscar64setup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
}
"Entry"
{
"MsmKey" = "8:_06971480436546E1B12DDC7EC9F704FD"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_0819C3D33D0942EF9E319C754E6C43D8"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
Expand Down Expand Up @@ -496,6 +502,12 @@
}
"Entry"
{
"MsmKey" = "8:_8E57961EDF0840A7A08877E8ED4826BC"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_8EBEED55D3F142769DE0A0014758447D"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
Expand Down Expand Up @@ -790,6 +802,12 @@
}
"Entry"
{
"MsmKey" = "8:_D52B954DFBCE4EB0932433DE7FCE9090"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_D76DA8C7D3964C93ABE193A7B53A0A9B"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
Expand All @@ -808,6 +826,12 @@
}
"Entry"
{
"MsmKey" = "8:_D9089340F2BF445B85880C886B30D7B7"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_DA28A07E7836459C99161100D7C102B8"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
Expand Down Expand Up @@ -1143,6 +1167,26 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_06971480436546E1B12DDC7EC9F704FD"
{
"SourcePath" = "8:..\\samples\\resources\\mouse.spd"
"TargetName" = "8:mouse.spd"
"Tag" = "8:"
"Folder" = "8:_758C6547998745659548D0656D380FEA"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_0819C3D33D0942EF9E319C754E6C43D8"
{
"SourcePath" = "8:..\\include\\gfx\\bitmap.h"
Expand Down Expand Up @@ -2643,6 +2687,26 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_8E57961EDF0840A7A08877E8ED4826BC"
{
"SourcePath" = "8:..\\include\\c64\\mouse.h"
"TargetName" = "8:mouse.h"
"Tag" = "8:"
"Folder" = "8:_247D4CAD3CB843B3A8A4DC2D90F47C28"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_8EBEED55D3F142769DE0A0014758447D"
{
"SourcePath" = "8:..\\samples\\particles\\fireworks_hires.c"
Expand Down Expand Up @@ -3623,6 +3687,26 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_D52B954DFBCE4EB0932433DE7FCE9090"
{
"SourcePath" = "8:..\\samples\\hiresmc\\paint.c"
"TargetName" = "8:paint.c"
"Tag" = "8:"
"Folder" = "8:_3E74C69B2EF64E938EA60950128C5A74"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_D76DA8C7D3964C93ABE193A7B53A0A9B"
{
"SourcePath" = "8:..\\samples\\stdio\\make.bat"
Expand Down Expand Up @@ -3683,6 +3767,26 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_D9089340F2BF445B85880C886B30D7B7"
{
"SourcePath" = "8:..\\include\\c64\\mouse.c"
"TargetName" = "8:mouse.c"
"Tag" = "8:"
"Folder" = "8:_247D4CAD3CB843B3A8A4DC2D90F47C28"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_DA28A07E7836459C99161100D7C102B8"
{
"SourcePath" = "8:..\\include\\c64\\memmap.h"
Expand Down Expand Up @@ -4450,15 +4554,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:oscar64"
"ProductCode" = "8:{F041F169-30F1-469E-BB7C-E316C7A562B5}"
"PackageCode" = "8:{B0EC0EC4-A9FC-496F-B024-6515FEB53CC0}"
"ProductCode" = "8:{D9D7E97A-B793-4546-B204-9518010E2DB9}"
"PackageCode" = "8:{40E0B5C5-53B2-4285-802B-FBA08B4E661D}"
"UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.14.181"
"ProductVersion" = "8:1.15.182"
"Manufacturer" = "8:oscar64"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down
1 change: 1 addition & 0 deletions samples/hiresmc/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
../../bin/oscar64 func3d.c -n
../../bin/oscar64 polygon.c -n
../../bin/oscar64 floodfill.c -n
../../bin/oscar64 paint.c -n
1 change: 1 addition & 0 deletions samples/hiresmc/make.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
call ..\..\bin\oscar64 floodfill.c -n
call ..\..\bin\oscar64 polygon.c -n
call ..\..\bin\oscar64 func3d.c -n
call ..\..\bin\oscar64 paint.c -n
Loading

0 comments on commit 946b1fe

Please sign in to comment.